My env says:
_=/usr/bin/env
and I have a question regarding the shebang, will the entry be correct if I type:
#!_ perl
?
My env says:
_=/usr/bin/env
and I have a question regarding the shebang, will the entry be correct if I type:
#!_ perl
?
No, it will not. In this case, the _
means the environment variable $_
, which is typically set to the last parameter on the previous line. It is not universally /usr/bin/env
.
However, a shebang does not expand environment variables. It consists of #!
, an optional space, the name of a command, and at most a space and one argument (some systems allow more, but not all do). So the shebang will try to execute the program _
, which is probably not what you intended.
Even if this did work, it would be confusing, and so you'd want to avoid it in clear code intended for use by others.
#!foo
does not make a $PATH lookup on Linux. (This is literally the reason people use #!/usr/bin/env foo
, relying on the 'env' utility to make a $PATH lookup.) Technically the OS will accept a relative name for the interpreter, like #!perl
, but it's ... relative to your current cwd() at the time of execution, so not very useful at all.
– u1686_grawity
Feb 20 '21 at 10:18
_
is set to "/usr/bin/env" is because you're using/usr/bin/env
to show it. Try showing it withpython
instead, likepython -c 'import os; print(os.getenv("_"))'
orperl
withperl -e 'print $ENV{"_"}."\n"'
and it'll show the path to your python or perl executable instead. – Gordon Davisson Feb 20 '21 at 03:14