What Is Wrong With This Bash Script File?
Hello everyone,
When I executing the following bash script file, -------------------- Foo=gcc\ -DDEBUG Goo=-I. Zoo=$(Foo) $(Goo) echo $(Zoo) -------------------- -------------------- ./test.sh: line 1: Goo: command not found ./test.sh: line 1: Foo: command not found ./test.sh: line 1: Zoo: command not found -------------------- I simply want to set three variables and test their output. Are there anything wrong with this script file? thanks in advance, George |
Don't put parentheses around the variable substitutions; just do $Foo. But this line should be different:
Code:
Zoo="$Foo $Goo" |
Or use ${Foo}
Read more over here: http://www.linuxcommand.org/ And don't forget the include the bash-header: Code:
#!/bin/bash |
I'm curious why you say to use exit at the end, instead of just naturally allowing EOF to terminate the script. Can Bash be configured to ignore EOF as a session terminator?
Also, I just want to point out, with respect, that I believe it's more flexible to use "#!/usr/bin/env bash" than "#!/bin/bash", since bash may not be installed into /bin (as it is not on BSD systems, for example). I think env is either stored in or symlinked in /usr/bin on every Unix-like installation. |
Hi taylor_venable,
Quote:
Zoo=$Foo\ $Goo regards, George |
Cool muha! Youe method works!
Quote:
regards, George |
Hi taylor_venable,
Quote:
regards, George |
@exit: it's something i picked up from over here: http://www.linuxcommand.org/wss0090.php#exit
I thought including exit on the last line of code caused a script to terminate succesfully (so no errors were made). |
The script exits with the result value of the last cmd run. If you want to set it explictly, use
exit <some_positive_integer_or_zero> conventionally on Unix style systems, zero is success, (positive) int is an error. iirc, negative value is not allowed here. |
From the manual page: "The env utility executes another utility after modifying the environment as specified on the command line. ... Probably the most common use of env is to find the correct interpreter for a script, when the interpreter may be in different directories on different systems. The following example will find the `perl' interpreter by searching through the directories specified by PATH."
Code:
#!/usr/bin/env perl |
Cool muha! I have never used it in this way before. I think there must be some default return values if I do not call exit explicitly at the last line of a script. Right?
Quote:
regards, George |
Thank you chrism01!
Quote:
regards, George |
Thank you taylor_venable!
Quote:
regards, George |
I mean, the current environment is applied to the program that env is going to execute. And by passing VARIABLE=value options to env, you can modify that environment. For example:
Code:
#!/usr/bin/env -S MY_ENV_VARIABLE=foo bash Quote:
Code:
/usr/bin/env bash |
Thanks taylor_venable!
Quote:
In the below scripts, Code:
#!/usr/bin/env -S FOO=foo GOO=goo bash Code:
[root@localhost root]# ./test3.sh Code:
#!/usr/bin/env FOO=foo GOO=goo bash Code:
[root@localhost root]# ./test3.sh regards, George |
All times are GMT -5. The time now is 10:23 AM. |