My env says:


and I have a question regarding the shebang, will the entry be correct if I type:

#!_ perl


  • 1
    The only reason _ is set to "/usr/bin/env" is because you're using /usr/bin/env to show it. Try showing it with python instead, like python -c 'import os; print(os.getenv("_"))' or perl with perl -e 'print $ENV{"_"}."\n"' and it'll show the path to your python or perl executable instead. – Gordon Davisson Feb 20 at 3:14

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.

  • The shebang line doesn't use $PATH. Or maybe it does somewhere, but it's not a general behaviour. – choroba Feb 20 at 0:38
  • In testing on Linux, it appears to, but I agree it's not documented, so I've updated the text. – bk2204 Feb 20 at 0:43
  • Normally #!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. – user1686 Feb 20 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.