Let's break this down into pieces.
This code runs the command :
with some arguments. The command :
does nothing and ignores its arguments. Therefore the whole command line does nothing, except whatever side effects happen in the arguments.
The syntax ${parameter_name:=value}
exists in all non-antique Bourne-style shells, including ash, bash, ksh and zsh. It sets the parameter to a default if necessary. It is equivalent to
if [ -z "$parameter_name" ]; then parameter_name=value; fi
… ${parameter_name}
In other words, if parameter_name
is not set or is set to an empty value, then set it to the indicated value; and then run the command, using the new parameter value. There is a variant, ${parameter_name=value}
, which leaves the parameter empty if it was empty, only using the indicated value if the parameter was unset.
You'll find this syntax documented under “parameter expansion” in the POSIX spec, and the dash, bash, ksh and zsh manuals.
There are variations on this syntax, in particular ${parameter_name:-value}
which let you use a default value for this expansion only, without assigning to the parameter.
In summary, : ${parameter_name:=value}
is a concise way of writing
if [ -z "$parameter_name" ]; then parameter_name=value; fi
An interactive shell is simply any shell process that you use to type commands, and get back output from those commands. That is, a shell with which you interact.
So, your login shell is interactive, as are any other shells you start manually, as described in the excerpt you quoted in your question. By contrast, when you run a shell script, a non-interactive shell is started that runs the commands in the script, and then exits when the script finishes.
The Bourne shell can be used as an interactive shell, just like bash
or tcsh
. In fact, many systems, such as FreeBSD, use sh
as the default user shell. Modern shells like bash
, zsh
, tcsh
, etc have many features that Bourne shell doesn't have, that make them more comfortable and convenient for interactive use (command history, completion, etc).
Interactive non-login shells (that is, shells you start manually from another shell or by opening a terminal window) don't read your .login
or .profile
files. These are only read and executed by login shells (shells started by the login
system process, or by your X display manager), so the commands and settings they contain are only applied once, at the beginning of your login session. So, when you start a terminal, the shell that it spawns for you does not read your login files (.login
for c-style shells, .profile
for bourne style shells), but it does read the .cshrc
, .bashrc
etc files.
Best Answer
You can always check the man page of your shell.
man bash
says:Therefore a shell script can check how many parameters are given with code like this: