如何在不进行修改的情况下使FreeBSD,OpenBSD和Linux上的bash脚本正常工作? [英] How do I get a bash script working on FreeBSD, OpenBSD and Linux without modifying it?

查看:182
本文介绍了如何在不进行修改的情况下使FreeBSD,OpenBSD和Linux上的bash脚本正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,标题可能有点恼人,但我没有更好的消息.无论如何,我希望bash脚本能够在FreeBSD,OpenBSD和Linux上运行而不进行修改,但是bash在Linux和BSD中不在同一位置.

Sorry, the headline might be a bit irritating, but I didn't know anything better. Anyway, I want a bash script to work on FreeBSD, OpenBSD and Linux without modifying it, but bash isn't located at the same place in Linux and BSD.

因此,如果我写#!/bin/bash,那么它将无法在BSD上运行,因为bash shell位于/usr/local/bin/bash中.有什么解决方案可以使此脚本在两者上同时起作用?

So, if I write #!/bin/bash then it won't work on BSD, because the bash shell is located in /usr/local/bin/bash there. Is there any solution to get this script working on both?

还是我真的需要提供两个具有不同路径的脚本吗??

Or do I really need to ship two scripts with different paths...?

推荐答案

在shebang(#!/usr/bin/env bash)中使用env应该会使脚本操作系统不可知.

Using env in the shebang (#!/usr/bin/env bash) should make the script OS agnostic.

这篇关于如何在不进行修改的情况下使FreeBSD,OpenBSD和Linux上的bash脚本正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆