How do I get a bash script working on FreeBSD, OpenBSD and Linux without modifying it?

爷,独闯天下 提交于 2019-12-03 13:16:11

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

TGOGAM

I like the answer about using #!/usr/bin/env bash It is an interesting and excellent answer, but that would only work if bash is in the path.

Another option might be to use #!/bin/sh which is the most universally compatible shell location. Then, have the script do something in sh, such as check where bash is installed (if bash is even installed). Another option might be to have bash exist to both locations. Making another installation may sound like overkill, but this goal could be accomplished as simply as creating a hard link so that bash actually exists in both locations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!