Greetings I have a general question. I just began my first lesson in Bash programming.
If I am in the Bash shell, why would my script not run unless preceded by /bin/bash?
When I do "set" to list my variables it says:
Yet if I make the script executable and do not precede it with /bin/bash - Bash tells me "command not found".
Not real important, just curious.
I am learning from a book, by the way.
Bash version is 3.2.39(1)release
Because there are a lot of script languages: php, perl, python, various shells, etc.
The Shebang tells the program loader, which interpreter to load, which in turn is given the script to execute.
Little trick to gain portability:
This will work on linux (/bin/bash) as well as e.g. a BSD (/usr/local/bin/bash)
Got it. I did read that, but did not digest it. Thanks.
Ok.Nothing works but /bin/bash in front of the executable name. The cheat code in the script does not work.
For now I will execute the script preceded by /bin/bash. I know the shells are standardized, bit confusing why I cannot put it in the script. Either the referenced material or your cheat.
I am Debian. Script created in Vi.
Can you please paste the shebang of your script in Code tags?
The head should look similar this:
write this and save:
echo "first script"
chmod 750 first_script.sh
Thanks. I was not using the . /
When using . / I was able to run it with #!/bin/sh as first line. But not #!/bin/env bash "/bin/env - bad interpreter".
I can either use /bin/bash before the executable. Or #!/bin/sh and . /
My first lesson was success. Putting the book away for now. Thanks for your assist. Thanks for the chmod cheat, too.
Oops, should have been