-
-
Notifications
You must be signed in to change notification settings - Fork 381
Discuss shebang #! in novice Bash lesson? #255
Conversation
Agree with "the mental overhead of this additional syntax is outweighed by the benefit of not having to remember which language the script is written in when you call it later". If we add some note about shebang in bash lesson I want to add similar note in |
We don't discuss shebang because we don't want to try to explain Unix |
On Sat, Jan 25, 2014 at 05:39:54PM -0800, Greg Wilson wrote:
That's a fair point. I'm attaching a PR here to document this |
On Sat, Jan 25, 2014 at 05:39:54PM -0800, Greg Wilson wrote: > We don't discuss shebang because we don't want to try to explain > Unix permissions to novices.
When I am telling people about the possibility to put everything they have just written line by line on the shell into a script file, I intentionally leave out that this script file should have a shebang. At that point people have no idea that there are different interpreters (let alone that there is something called an interpreter). A better point to introduce this would be when starting with Python (which always(?) comes after the shell introduction): "Wouldn't it be neat if I could start the Python script just by writing the name without having to put 'python ' first?" |
On Sat, Jan 25, 2014 at 08:22:42PM -0800, Steven Koenig wrote:
Do you have them invoke their scripts with: $ bash ./my-script or with: $ ./my-script relying on their current shell to be compatible? |
I teach them: bash my-script.sh by analogy with python my-script.py |
Thanks @wking. I think the rationale is useful, and am +1 for merging. |
Discuss shebang #! in novice Bash lesson?
@wking: Rely on the shell being compatible, since it definitely is under the circumstances lined out above. Explaining that weird "./" in front of the script name is enough at that point. |
The novice lessons currently don't discuss the shebang. I don't have solid numbers, but I have seen very few scripts without these leading comments, which are useful for typing reduction, and also to avoid accidentally running a Bash script from a POSIX shell (or other mix-ups). I think the mental overhead of this additional syntax is outweighed by the benefit of not having to remember which language the script is written in when you call it later.
This is more of a Unix-ism than a shell-specific feature, but the Bash scripting lesson seems like a good place to address it.