trysis
trysis

Reputation: 8416

Shell Commands: Identical Parameters, Different Values

In Bash and other shells, many commands can take parameters that do different things (in reality, the "commands" are files, but bear with me here). For example, with mongod -f ~/mongo.conf --quiet --port 8070 --bind_ip 127.0.0.2 --dbpath ~/data/db --ipv6, we are calling the mongod command (actually the mongod or mongod.exe file somewhere in the system's PATH) with the parameters -f ~/mongo.conf, which has the Mongo daemon use the configuration file at ~/mongo.conf; --quiet, which suppresses error and other messages; --port 8070, which has the server use port 8070; --bind_ip 127.0.0.2, which has the server use IP address 127.0.0.2; --dbpath ~/data/db, which has Mongo store its databases at ~/data/db, and --ipv6, which has Mongo broadcast on IPv6 as well as IPv4.

What I am asking is how do shells usually deal with commands using multiple parameters which are identical but where the user inputs different values for each copy? Does the shell use the first or last copy or something in the middle? Does it even allow multiple identical parameters? For example, if I try to run the command (again, technically file) npm ls --depth 0 --depth 2 --depth 6 --depth 2, to tell the npm package manager how many levels deep to list dependencies from at the maximum, would it list dependencies a maximum of 0, 2 or 6 levels deep? Or would it tell me to go away and stop wasting its time with frivolities?

I am mainly asking this question for UNIX-based shells like bash, sh, csh, and dash, but would welcome information about other shells like cmd and Powershell.

Upvotes: 0

Views: 35

Answers (1)

John1024
John1024

Reputation: 113814

"What I am asking is how do shells usually deal with commands using multiple parameters"

As an example:

npm ls --depth 0 --depth 2 --depth 6 --depth 2

The shell sees this as a command name, npm, followed by nine arguments. The shell does not know or care what those arguments are or that a human might be confused by those various different values "depth". The shell merely takes those nine strings and passes them as arguments to npm. The interpretation of those values is entirely up to the code in the executable.

Some executables might return an error message. Some may assume that later values override earlier. Whatever it does, it is up to the whim of the person who programmed that executable. This should all be specified in the documentation for the command, not the shell.

Upvotes: 1

Related Questions