UbuntuThis forum is for the discussion of Ubuntu Linux.
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.
The posted code snippet doesn't tell us what it is you are trying to do. $TYPE isn't mentioned, just the check is shown. $TYPE_N is mentioned, but not checked.
I do see one thing that probably doesn't work as expected:
Code:
env PATH=$SOMETHING:$PATH ......
echo " "
if [ $? -ne 0 ]; then ....
The if statement checks if the previous command was executed successfully. The previous command being echo " ", not the env .... command!
The second if command (if [[ $TYPE == "some_type" ]] ; then) could fail if $TYPE is empty. If $TYPE is empty the command will look like this: if [[ == "some_type" ]] ; then, which is syntactically incorrect and bash will complain.
You can solve this by putting double quotes around the variable: if [[ "$TYPE" == "some_type" ]] ; then.
This PATH=$SOMETHING:$PATH will prepend the content of $SOMETHING to your PATH (whatever $SOMETHING may be).
This part $MUNGE $CKPT/$TYPE_N doesn't make too much sense, it (the env command) will try to execute /home/mahmood/scripts/munge.py and $CKPT/flex_001 ($CKPT isn't mentioned in your code snippet).
All output created by the env command is redirected to /home/mahmood/checkpoints/flex_001.
Without knowing what you are trying to accomplish, the env ..... statement doesn't make too much sense. The environment is not meant to execute commands, it holds variables that can be set and unset which are used by other programs.
env PATH=$SOMETHING:$PATH $MUNGE $CKPT/$TYPE_N > $CKPT_BASE/$TYPE_N.munge_output
if [ $? -ne 0 ]; then
echo "Munge failed!"
exit -1
I know that $? shows the return code of the previous command, but what is the return code of env command? what does it mean when env returns 0 or anything else?
Exit code 0 means that the command was executed successfully. In general any other number means that the command did not run successfully. You do need to look at the man page for that command for their specific meaning, grep for example can throw an exit code of 1, which means that no hit was found (which isn't an error).
If you want to know the specific exit status of the env command try: echo $1 ; exit (in between the env .... command and the if [$? -ne 0 ]; part.
BTW: an exit code is, too my knowledge, always positive. 0 being OK, none zero being not OK (or special). This: exit -1 is incorrect, that should be exit 1 (positive number, one or higher).
Most of the time it is a forgotten opening/closing X. X could be a (double) quote, bracket, brace etc. Syntax highlighting helps in catching these typo's/mistakes.
You can also create stop points yourself. Like the one I posted in post #6 (the echo $1 ; exit).
You can also use the set -x option (immediately below the #!/bin/bash line), it is meant for debugging.
That "set -x" was useful. I have attached the script file (since I couldn't upload *.sh file, I renamed it to *.txt!!) and the log file which shows the debug information. The error is at line 115 of log.txt.
I will be thankful if you have a look at it.
Thanks,
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.