I am trying to understand this piece of code:
. functions.sh || { : ; echo "Error while loading the specified file" >&2; exit 2; }
I get that the code in the bracket is called when the specified file isn't available. But what does this : ;
mean?
Moreover, when you delete it, then the script doesn't work.
Bash and sh both use colons (":") in more than one context. You'll see it used as a separator ($PATH, for example), as a modifier (${n:="foo"}) and as a null operator ("while :"). You'll also see the null operator usage in "if-then" sections: if [ "$T1" = "$T2" ] then : else echo "Nope" fi.
A double pipe (||) causes the following command to be executed only if the preceding command returned an exit status of non-zero. $ cat bf5 grep $1 /usr/lib/spell/list || echo "not in dictionary" $ bf5 cochise not in dictionary. Test. The test command is used to check conditions in the Bourne Shell.
It is used when a command is needed, as in the then condition of an if command, but nothing is to be done by the command.
When the shell sees a semicolon (;) on a command line, it's treated as a command separator -- basically like pressing the ENTER key to execute a command.
The colon is null statement, so it does nothing. The semi-colon ends a list of commands.
Not sure why anyone would write the above, it's basically "do nothing, then do the echo
" which seems like it could be simplified. Could be somebody's copy-paste baggage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With