swcarpentry / shell-novice

The Unix Shell
http://swcarpentry.github.io/shell-novice/
Other
375 stars 972 forks source link

Adding a note on when to use - vs -- #1405

Closed GentleInfant closed 1 year ago

GentleInfant commented 1 year ago

Something I've often found is that people don't know when to use - vs -- for options when both alternatives exist and, more often than not, just use - everywhere. Back when I was a lad the rule-of-thumb I was taught was that you use - when tying command directly into the shell, in order to minimise the amount of typing you do, and use -- in scripts since they'll be read far more than they'll be written so clarity is more important.

I would like to propose adding a Tip to the second lesson where they are introduced that says something like:

When to use -- or -

When to use the long options or the short options depends on what you are doing at the time. The general good practice rule-of-thumb is:

  • Use the single character options following - when typing commands to be run immediately in order to minimise the amount of typing you do.
  • Use the longer options following -- when using the commands inside a script file. Script files are usually read far more frequently than they are added to so clarity is more important than saving key strokes.
bkmgit commented 1 year ago

Thanks for the suggestion. Can you make a pull request?