Using --  to separate options from filenames

In our mkcd example, we preceded both calls to "$1" with a double dash, --, the option terminator string. This syntax specifies a point beyond which further arguments are meant as argument strings for the program, often filenames, and not as options, even if they start with hyphens, such as -dirname-.

This is so that the mkdir and cd commands know that whatever we pass in as $1 is not an option to the command, such as -p or --version, but a directory name on which to operate. Most commands that accept options use this syntax to separate options from filenames or other words, including bash itself:

bash$ bash --version GNU bash, version 4.4.23(1)-release (x86_64-pc-linux-gnu) bash$ bash -- --version ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.