Doubt about shell script

Asked

Viewed 151 times

2

I’m studying linux, and it’s my first contact with the shell script, the documentation I wanted to do is the following:

#!/bin/bash

if [ uname - m = "x86_64" ]; then
  echo "sua versão é de 64bits"
else
  echo "sua versão é de 32bits"
fi

I tried to use this one I did, but it’s not working.

2 answers

3


You have to read how the comparison works in Shell, it does not only accept to put the direct command in the comparison.

What you should do is store the value in a variable and then compare that variable with the value you want:

#!/bin/bash

resultado=`uname -m`
if [ $resultado = "x86_64" ]; then
  echo "sua versão é de 64bits"
else
  echo "sua versão é de 32bits"
fi

Note: As you can see, to execute a command and store it in a variable, you need to use the grave accent (``) and put the command inside it.

0

Or could use the new standard adopted!:

resultado = $(uname -m)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.