Let's break down the line of interest.
:
is a do nothing in shells.
;
is a command separator.
exec
will replace the current process with the process of the command that it is executing.
Notice that in the exec command it passes "$0"
and "$@"
as parameter to the command?
This will allow the new process to read the script denoted by $0
and use it as a script input and reads the original parameters as well $@
The new process will read the input script from the beginning and ignore the comments like #!/bin/sh
. and will also ignore :
.
Here's the trick. Most interpreters, including perl, uses syntax that are ignored by shell or vice-versa so that on re-reading the input file, the interpreter will not exec itself again.
In this case, the new process ignored the whole line from :
. The reason why the rest of the line is ignored? On some c like interpreters, //
is a comment.
I forgot to answer your question. Yes it seems portable. There may be corner cases but I can't think of any right now.