I am working on some bash scripts that I'd like to work across my Linux and FreeBSD systems.
Since I mostly work in Linux, I am used to starting my bash scripts with
#!/bin/bash
But this doesn't work on FreeBSD since bash lives at /usr/local/bin/bash
. So on FreeBSD my scripts need to start with
#!/usr/local/bin/bash
So is there something else I could use that would be portable across both systems? I'd rather not maintain two versions of the scripts.
#!/usr/bin/env bash
should do the trick, provided that bash is on the path somewhere. See here for more details.
Honestly, if you want portability, invoke as /bin/sh and code to POSIX. It's less pretty, but you will run into fewer potential issues if you do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With