What does $0
mean?
From man bash
, section PARAMETERS
, subsection Special Parameters
:
0 Expands to the name of the shell or shell script. This is set
at shell initialization. If bash is invoked with a file of com‐
mands, $0 is set to the name of that file. If bash is started
with the -c option, then $0 is set to the first argument after
the string to be executed, if one is present. Otherwise, it is
set to the file name used to invoke bash, as given by argument
zero.
It says 0
there, but $0
is meant because $
identifies a parameter.
You can find such information in man pages easily by using the search key /
. Just type /\$0
followed by return. The $
has to be quoted as \$
in this case because the $
has a special meaning when searching, and the backslash is needed to "escape" this special meaning.
In what cases ";" is used at the end of statement in a script?
Usually only when you want to put at least two statements in a single line, for example this would be a case where you can use ;
:
if [ $i = $myname ]; then
There's no case in your example script where the ;
is required, you can remove it from the first line. Details can again be found in man bash
:
Lists
A list is a sequence of one or more pipelines separated by one of the
operators ;, &, &&, or ||, and optionally terminated by one of ;, &, or
<newline>.
[...]
A sequence of one or more newlines may appear in a list instead of a
semicolon to delimit commands.
If a command is terminated by the control operator &, the shell exe‐
cutes the command in the background in a subshell. The shell does not
wait for the command to finish, and the return status is 0. Commands
separated by a ; are executed sequentially; the shell waits for each
command to terminate in turn. The return status is the exit status of
the last command executed.