Related: Which shell interpreter runs a script with no shebang?
The script does not have a shebang/hashbang/#!
line, simply because a double dash is not #!
.
However, the script will be executed by a shell (see above linked question and answers), and in that shell, if -
is a valid character in a function name, the line declares a shell function called --
that does nothing (well, it runs :
, which does nothing) and which is never called.
The function, in the more common multi-line notation (just to make it more obvious what it looks like, as its odd name kinda obscures the fact that it's in fact a function):
-- () {
:
}
The sole purpose of the function definition is to have a line that is valid in a shell script and at the same time a valid SQL command (a comment). This sort of code is called a polyglot.
After declaring the bogus shell function, the script, when executed by a shell script interpreter, uses exec
to replace the current shell with the process resulting from running db2 -txf "$0"
, which would be the same as using db2 -txf
on the pathname of the script from the command line.
This trick would probably not work reliably on systems where dash
or other ash
-based shells, yash
, the Bourne shell, ksh88
or ksh93
is used as /bin/sh
, as these shell do not accept functions whose name contains dashes.
Also related:
I suppose the following would also work (not really tested):
--() { exec db2 -txf "$0"; }; --