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
From man zshoptions
HIST_VERIFY
Whenever the user enters a line with history expansion, don't execute the line
directly; instead, perform history expansion and reload the line into the editing buffer.
To disable this option run setopt no_hist_verify
. You can also have a look at your config file and remove the hist_verify option or just explicitly disable it.
Best Answer
[]
is shortcut oftest
command.According to
man test
:So if you running bash as interactive shell (terminal - see this thread for terminology explanation), bash will be replaced by zsh.
More about .bash* files:
Stéphane Chazelas comment:
Note that a shell can be interactive without stdout being a terminal, and a shell can be non-interactive with a terminal on stdout (like anytime you run a script within a terminal without redirecting/piping its output), and
bash
can read.bashrc
even when not interactive (like inssh host cmd
wherebash
is the login shell of the user on host, orbash --login -c 'some code'
).case $- in *i*)...
is the correct way to test if a shell is interactive.