What Does Exec ${perl-perl} -sx $0 ${1+"$@"} Mean In Shell Script?
I'm given a task to convert a shell script which contains Shell script, Perl code to Python. I managed to convert the Perl code to Python. But there is this shell script statement
Solution 1:
${PERL-perl}
is a parameter expansion: if the PERL
shell variable is unset, use perl
, else use the content of PERL
. (Arguably, this should be ${PERL:-perl}
, because if PERL
is set but empty, the empty string will be used.)
${1+"$@"}
stands for "if $1
is set, use "$@"
(all positional parameters), else substitute null". This is a hack for older shells that get confused by "$@"
if there are no positional parameters and expand to a single parameter instead of none at all. Bash would work with just "$@"
instead.
For the options to perl
, see perldoc perlrun
.
Post a Comment for "What Does Exec ${perl-perl} -sx $0 ${1+"$@"} Mean In Shell Script?"