-1

Basy manual says that for the command bash:

-s

If this option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell.

I was wondering how to understand "if no arguments remain after option processing"?

For example, bash -c "echo hello" doesn't read commands from the standard input, while there is "no argument remaining after option processing", because "echo hello" is an argument for option -c, and option processing processes both options and the arguments for them.

Thanks.

5

You can’t take sentences, or even portions of sentences in this case, from the Bash manual and expect them to make sense on their own. You need to read the “ARGUMENTS” section of the manpage, or the last paragraph of the “Invoking Bash” section:

If arguments remain after option processing, and neither the -c nor the -s option has been supplied, the first argument is assumed to be the name of a file containing shell commands (see Shell Scripts). When Bash is invoked in this fashion, $0 is set to the name of the file, and the positional parameters are set to the remaining arguments. Bash reads and executes commands from this file, then exits. Bash’s exit status is the exit status of the last command executed in the script. If no commands are executed, the exit status is 0.

“If no arguments remain after option processing” is the opposite of this, and its effect should be understood alongside the effects of the -c and -s options. If you specify -c, then that takes precedence:

Read and execute commands from the first non-option argument command_string, then exit. If there are arguments after the command_string, the first argument is assigned to $0 and any remaining arguments are assigned to the positional parameters. The assignment to $0 sets the name of the shell, which is used in warning and error messages.

So here’s how you should understand “if no arguments remain after option processing”:

  • process all the options, including effects determining what the shell will do with its arguments and input (-c and -s in particular);
  • once that’s done, if the shell’s behaviour hasn’t been fixed yet, and no arguments remain, then ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.