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

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

bash - 什么是首选的Bash shebang?(What is the preferred Bash shebang?)

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

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

1 Answer

0 votes
by (71.8m points)

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 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...