What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?

后端 未结 5 690
谎友^
谎友^ 2020-11-28 00:05

In the header of a Bash script, what\'s the difference between those two statements:

  1. #!/usr/bin/env bash

  2. #!/usr/bin/bash<

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 00:48

    I find it useful, because when I didn't know about env, before I started to write script I was doing this:

    type nodejs > scriptname.js #or any other environment
    

    and then I was modifying that line in the file into shebang.
    I was doing this, because I didn't always remember where is nodejs on my computer -- /usr/bin/ or /bin/, so for me env is very useful. Maybe there are details with this, but this is my reason

提交回复
热议问题