Skip to content
This repository has been archived by the owner on Jan 3, 2018. It is now read-only.

Discuss shebang #! in novice Bash lesson? #255

Merged
merged 1 commit into from
Jan 27, 2014

Conversation

wking
Copy link
Contributor

@wking wking commented Jan 26, 2014

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.

@rgaiacs
Copy link

rgaiacs commented Jan 26, 2014

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 python/novice/06-cmdline.ipynb and some place in R lesson or point to the bash note.

@gvwilson
Copy link
Contributor

We don't discuss shebang because we don't want to try to explain Unix
permissions to novices.

@wking
Copy link
Contributor Author

wking commented Jan 26, 2014

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.

That's a fair point. I'm attaching a PR here to document this
reasoning.

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.
@stevenkoenig
Copy link

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?"

@wking
Copy link
Contributor Author

wking commented Jan 26, 2014

On Sat, Jan 25, 2014 at 08:22:42PM -0800, Steven Koenig wrote:

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).

Do you have them invoke their scripts with:

$ bash ./my-script

or with:

$ ./my-script

relying on their current shell to be compatible?

@gvwilson
Copy link
Contributor

I teach them:

bash my-script.sh

by analogy with

python my-script.py

@ahmadia
Copy link
Contributor

ahmadia commented Jan 26, 2014

Thanks @wking. I think the rationale is useful, and am +1 for merging.

gvwilson pushed a commit that referenced this pull request Jan 27, 2014
Discuss shebang #! in novice Bash lesson?
@gvwilson gvwilson merged commit 0d8f4dd into swcarpentry:master Jan 27, 2014
@wking wking deleted the no-shebangs branch January 27, 2014 21:39
@stevenkoenig
Copy link

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants