什么是首选的 Bash shebang?

编程入门 行业动态 更新时间:2024-10-28 18:31:22
本文介绍了什么是首选的 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?

本文发布于:2023-10-20 21:18:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1512155.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:首选   Bash   shebang

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!