Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there any Bash shebang objectively better than the others for most uses?

(在大多数情况下, Bash shebang是否客观上比其他人更好?)

  • #!/usr/bin/env bash
  • #!/bin/bash
  • #!/bin/sh
  • #!/bin/sh -
  • etc

    (等等)

I vaguely recall a long time ago hearing that adding a dash to the end prevents someone passing a command to your script, but can't find any details on that.

(我模糊地回忆起很久以前的一次听说,在最后添加一个破折号可以防止有人将命令传递给你的脚本,但是找不到任何有关它的细节。)

  ask by Kurtosis translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
415 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should use #!/usr/bin/env bash for portability : different *nixes put bash in different places, and using /usr/bin/env is a workaround to run the first bash found on the PATH .

(你应该使用#!/usr/bin/env bash来实现可移植性 :不同的* nixes将bash放在不同的地方,使用/usr/bin/env是一种解决方法来运行在PATH上找到的第一个bash 。)

And sh is not bash .

(而sh不是bash 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...