Why is variable in bash script executing as a command when I run it?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I just want to get the output of that command, which should be 0 or 3 if it fails and run the command without echo $? if it's not 0 or 3. So something like:
if [[ "$ipaCheck" == 0 || "$ipaCheck" == 3 ]]; then
exit 0
elif [[ "$ipaCheck" != 0 ]]; then
$ipaInstall
else
echo "Something is wrong. Please contact support."
fi
Your confusing output of a command with its exit status.
Every linux command executed by the shell script or user returns an exit status i.e a number (0-255) which is stored in the variable $?
You do not need command substitution but to get the exit status the command needs to be executed.
I decided to just check if the file that gets created exists or not. This works when I curl the script and run it but it still executes the command if I curl another script that curls this script:
By doesn't work, I mean that it still is executing the command from the else condition if I curl the script that curls the ipaEnroll script. If I just curl the ipaEnroll, it works fine. It's like it's completely ignoring the condition.
Normally a web server can not execute bash scripts directly from its document root and is considered a big security hole. So how is your system configured?
I have not examined the entire process yet but it is probably some environment thing.
if [[ "$ipaCheck" == 0 || "$ipaCheck" == 3 ]]; then
exit 0
you can use case
Code:
case "ipaCheck" in 0 | 3 ) exit 0 ;; esac
but this won't work
Code:
elif [[ "$ipaCheck" != 0 ]]; then
$ipaInstall
else
echo "Something is wrong. Please contact support."
After the first test the failure of the second would mean only that value of ipaCheck is non-numerical - in case of bash exits complaining about mismatching types and none of $ipaInstall or echo .. will be ever executed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.