本文介绍了什么是首选的 Bash shebang?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何 Bash shebang 客观上比大多数用途更好?
Is there any Bash shebang objectively better than the others for most uses?
- #!/usr/bin/env bash
- #!/bin/bash
- #!/bin/sh
- #!/bin/sh -
- 等
我依稀记得很久以前听说在末尾添加破折号可以防止有人向您的脚本传递命令,但找不到任何详细信息.
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.
推荐答案你应该使用 #!/usr/bin/env bash for 可移植性:不同的*nixes put bash 在不同的地方,使用 /usr/bin/env 是一种运行在 PATH 上找到的第一个 bash 的解决方法.而 sh 不是 bash.
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. And sh is not bash.
更多推荐
什么是首选的 Bash shebang?
发布评论