0

Bash manual says:

An interactive shell is one started without non-option arguments, unless -s is specified, without specifying the -c option, and whose input and output are both connected to terminals (as determined by isatty(3)), or one started with the -i option.

I was wondering which "unless -s is specified" applies to:

  • "without non-option arguments", or
  • "without specifying the -c option"?

Can you rephrase the quote more clearly to enumerate all the ways to start an interactive shell? (I am only clear that I can start one by -i alone, but not sure about the other way(s) which the quote describes.)

Thanks.

Tim
  • 101,790

1 Answers1

4

“unless -s is specified” qualifies “without non-option arguments”. The synopsis for bash is

bash [options] [command_string | file]

Non-option arguments are command_string or file. If you specify either of these, the resulting shell isn’t interactive, unless you specify -s, without specifying -c. -s causes the arguments to be assigned to the positional parameters instead of being interpreted:

bash -s arg1 arg2

opens an interactive shell, and

echo $*

outputs

arg1 arg2

So you can open an interactive Bash shell using either of the following:

  1. ensure the standard input and output are connected to a terminal and specify no non-option arguments;
  2. ensure the standard input and output are connected to a terminal and specify -s with any arguments apart from -c;
  3. specify -i.

If you specify both -c and -s, -c takes precedence (it’s processed earlier). The resulting shell is non-interactive and processes the given command.

Stephen Kitt
  • 434,908
  • Thanks. What kind of shell is it, if the standard input and output are connected to a terminal and "specify both -s and -c"? – Tim Apr 05 '18 at 17:36
  • One might do well to refer to https://unix.stackexchange.com/questions/277312/ from 2016 at this point. – JdeBP Apr 05 '18 at 21:16
  • Thanks. Still confused. In "without non-option arguments, unless -s is specified, without specifying the -c option", (1) which is the "unless" clause: "unless -s is specified", or "unless -s is specified, without specifying the -c option"? (2) What does "non-option argument" mean? If an option expects an argument following it, is an argument following it a non-option argument? For example, is "echo hello" in bash -c "echo hello" a nonoption argument? – Tim Apr 06 '18 at 19:35
  • (cont) (2) In bash -c "echo hello", if I am correct, "echo hello" is called an option argument, so there is no nonoption argument and it fits the first bullet point in your reply. But the shell it created isn't interactive. – Tim Apr 06 '18 at 20:03