Home > database >  Bash script not returning output
Bash script not returning output

Time:10-25

I am practicing writing simple bash scripts. I wrote the following script in TextEdit and saved it as a .sh file.

for x in “$@“
do
    if x = 0; 
        then
            echo “False”
    elif x = 1; 
        then
            echo “True”
    fi
done

When I call this script in XQuartz using the following syntax, it runs forever and does not output anything. What am I doing wrong?

sh TestBash.sh 0 1 0 1

CodePudding user response:

See http://mywiki.wooledge.org/ArithmeticExpression

To compare the x variable to an integer:

((x == 0))

CodePudding user response:

for x in "$@"
do
    if ((x == 0)); 
        then
            echo "False"
    elif ((x == 1)); 
        then
            echo "True"
    fi
done
  • Related