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?
Advertisement
Answer
The short answer is that you only get one parameter to the interpreter which is specified via the “#!” mechanism. That became “bash -x”.
Usually the limitation is more apparent, e.g., using
#!/bin/bash -x -i
would pass “-x -i” as the parameter, and get unexpected results.
Sven Mascheck comments on this in his page on the topic:
most systems deliver all arguments as a single string