Thomas Thomas - 1 year ago 58
Bash Question

what is the dash used for in shell command argument parsing?

I'm a new linux learner, and I don't know why we use a dash for parameters of Shell. As I know, $1, $2 ... are the first, second parameter.

So my question is:

When do we need/needn't a dash for a patameter?

For me, when I write some my own shell script, I always pass parameters without dash. For example, param1 param2 param3

However for other shell scripts, we use dash. For example
ls -l myDir
. If I'm right, there are two patameters for
. Why do we use a dash for
but not for

Answer Source

Hyphen (-) is used to differentiate the options with other arguments.

I am using your example ls -l myDir to explain. How will you differentiate whether l is option to output long lists or you want to list a file named l?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download