I am passing command line arguments to a script, say a.sh.
From a.sh, I use "$@" to pass all those arguments to another bash script (user_pref.sh). In this bash file, I am trying to assign either 0 or 1 based on the parameters received from a.sh using basic if condition. But for some reason, I am not able to reason the correct value and all my variables are set to 0. I am new to bash scripting and would really appreciate any help here. I have referred different post on the site but they have not helped me resolve my issue so far.
a.sh code
#!/bin/bash /home/postgres/viraltest_scripts/user_pref.sh "$@" &> /home/postgres/viraltest_scripts/logs/refresh_dev_sql.log user_pref.sh Code:
#!/bin/bash ## assigning default values a=1 b=1 c=1 if [[ $1 -eq 0 ]] then a=0 fi if [[ $2 -eq 0 ]] then b=0 fi if [[ $3 -eq 0 ]] then c=0 fi Irrespective of what I pass from a.sh, All the variables in user_pref.sh are assigned 0. Can anyone point out what am I doing wrong with the If statement? PS: I am aware of assigning a=$1 but for the purpose of my application, I have to explicitly assign 0 or 1 instead of doing a=$1.
[[ non_integer_value -eq 0 ]]is true and does not emit any error message.a.sh? It is difficult to know exactly what you are trying to accomplish otherwise. Thanks!/bin/shmay not be what you think it is. If you want bash, say so. Try running withbash -x a.shto see what's happening.