On Thu, Feb 06, 2003 at 04:33:25AM -0800, Paul Mackinney wrote: > One point is that #/bin/sh is generally preferred over #!/bin/bash as a > script header. This works fine because on every Linux system I've fooled > with, /bin/sh is a symlink to /bin/bash. From the Bash man page: > > If bash is invoked with the name sh, it tries to mimic the startup > behavior of historical versions of sh as closely as possible, while > conforming to the POSIX standard as well ...
Unfortunately, it still allows for almost all bashisms, which don't run
on non-Linux systems at all.
> PS: Two questions: 1) I grok basename, but not ${0##*}. Could someone
> explain? 2) Is there really any difference between `basename $0` and
> $(basename $0)?
1) from the FreeBSD version of sh(1):
${parameter##word}
Remove Largest Prefix Pattern. The word is expanded to produce a
pattern. The parameter expansion then results in parameter, with
the largest portion of the prefix matched by the pattern deleted.
You missed the / at the end, so ${0##*/} would strip off all characters
including the last slash, ie the same effect as basename.
2) I believe the first form using backquotes is more portable, but I may
be wrong. $() is POSIX behaviour at least so most modern unices should
support it.
--Stijn
--
I really hate this damned machine
I wish that they would sell it.
It never does quite what I want
But only what I tell it.
msg00777/pgp00000.pgp
Description: PGP signature
