I tried to pass parameters to bash in shebang of executable script:

#! /usr/bin/env bash -ex


But I get an error:

/usr/bin/env: ‘bash -ex’: No such file or directory

Should I avoid to use /usr/bin/env in favor of /bin/bash to avoid error, or there is a way to stick with /usr/bin/env?

I am on Ubuntu 16.04.3.

  • Put set -ex in your script? – muru Jan 29 '18 at 6:56
  • It is not an option. The script intended for standalone using (directly with default environment, when I debug it) and for calling from another script, where set -ex is superfluous. – Tomilov Anatoliy Jan 29 '18 at 7:04
  • Then you don't need it in the shebang. – muru Jan 29 '18 at 7:05
  • I want to type just ./script, or even script if dirpath in $PATH. Surely I can type bash -ex $( which script ), but it is too wordy. – Tomilov Anatoliy Jan 29 '18 at 7:19
  • Also related, but the opposite question: unix.stackexchange.com/questions/361794/… – Kusalananda Jan 29 '18 at 7:49

Browse other questions tagged or ask your own question.