Can I run Bash scripts in FreeBSD without modifying them?
You can call your favorite shell with the script as a parameter.
bash ./script.sh
I run FreeBSD myself. I found that starting the script with the following greatly improves cross OS compatibility:
#!/usr/bin/env bash
You asked to correct you when you were wrong. I'll try:
- Linux scripts are written in bash: Well, some are written for
bash
, others fordash
and hopefully a lot potable for any POSIX-compliant shell. - Bash script usually #!/bin/sh If they rely on non-standard
bash
features, it is highly recommended to have a#!/bin/bash
shebang - In GNU/Linux, /bin/sh is Bash That depends on the distribution. It can also be
dash
ormksh
on Debian for instance. - In FreeBSD, /bin/sh is not bash, it's the true sh. There is a lot of
sh
implementations. Which one is "true"? On FreeBSD,sh
is based on the Almquist shell likedash
or NetBSDsh
. On OpenBSD, it's based onpdksh
, on many commercial Unices, it's based on ksh88 (which is the basis for the Unix/POSIXsh
specification). Someksh88
-based shells andbash
are the only two shells that have been certified as being a Unix compliantsh
implementation (when built with the right flags and in when in the right environment).
If you have scripts with /bin/sh
shebang and want them to be executed by zsh
you can try passing the script to zsh
, but this will fail as soon as this script calls another script (and you don't want to modify it).
So I only see the possibility to have a symbolic link from /bin/sh
to your zsh
. But I don't recommend to do this, as it may have drastic impact on your boot time and will not even help you for some of your linux scripts.