Variable assignment in sh
freebsd at edvax.de
Wed Feb 1 16:23:29 UTC 2017
On Wed, 1 Feb 2017 10:06:33 -0500, Roger Pate wrote:
> On Tue, Jan 31, 2017 at 8:26 PM, Manish Jain
> <bourne.identity at hotmail.com> wrote:
> > A point here for bash scripting.
> Most often, but not always, if I need something bash has and /bin/sh
> lacks, it's time to write that script in a different language. :P
Don't confuse sh with bash, they're not fully interchangeable.
While sh ("classic Bourne shell") is quite portable and usually
POSIX, bash is not. Even on Linux, sometimes bash != bash, and
sometimes it's dash. You can see bash as a superset of sh, so
you can do testing of sh scripts with bash quite well, even
in the "line by line" interactive manner.
If you need stuff to work across different operating systems,
sh is often called "lowest common denominator" as most UNIX
systems default to it as scripting shell. If you need "bash-isms"
(features that bash has, but sh doesn't), there are also some
portable ways to deal with the shebang line, but don't assume
that bash is installed everywhere as /bin/bash. :-)
Of course you are right: When you reach the border of what a
shell language can do, consider using better tools, more suitable
for the task you want to solve. For example, if you find yourself
in a while read something | cut | cut | sed | grep | sed | sort
piping chain, consider using awk. :-)
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions