Variable assignment in sh

Manish Jain bourne.identity at
Wed Feb 1 01:26:10 UTC 2017

On 02/01/2017 06:18 AM, Polytropon wrote:
> Additionally, it helps to write portable scripts (across
> different operating systems), not just for FreeBSD systems

A point here for bash scripting. I earlier used to shebang with the path 
to bash :


Since my scripts sometimes needed to be ported to Linux and/or Cygwin, I 
often hacked the system with a symlink /bin/bash that pointed to the 
actual bash. Then I would use the symlink path - that worked under both 
FreeBSD and Linux.

But a much better way now exists with env :

#!/usr/bin/env bash

The above shabang always works, no matter what the system, is fully 
portable, and is not too much typing either.

Manish Jain

More information about the freebsd-questions mailing list