Doubt about shell script

1

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

#!/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 is not working.

    
asked by anonymous 01.09.2018 / 21:52

1 answer

1

You have to read how the comparison works in Shell, it does not just accept the direct 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, in order to execute a command and save it to a variable, it is necessary to use the grave accent ('') and put the command inside.     

01.09.2018 / 22:41