Why does "/usr/bin/env bash -x" only work in command line?

I am playing with a docker CentOS image, and find executing “/usr/bin/env bash -x” command is OK in terminal:

bash-4.1# /usr/bin/env bash -x
bash-4.1# exit
+ exit
exit

But after writing this command into a script and execute it, it doesn’t work, and prompts “No such file or directory“:

bash-4.1# ls -lt a.sh
-rwxr-xr-x. 1 root root 23 May 20 04:27 a.sh
bash-4.1# cat a.sh
#!/usr/bin/env bash -x
bash-4.1# ./a.sh
/usr/bin/env: bash -x: No such file or directory

Is there any difference between two methods?


Source: shell

Leave a Reply