Paul Eggert writes on Tue, 27 Mar 2018 18:38:54 -0700:
>> ...
>> > test=${1##*/}
>> >
>> > I would strongly urge removal of such shell extensions.
>>
>> That syntax has been standard ever since POSIX formalized the shell in
>> IEEE Std 1003.2-1992 (I just pulled out my trusty printed copy and
>> checked). It's a bit of a stretch to call it an "extension" 26 years
>> after standardization.
>> ...
I just looked up that standard (page 37) and tried its several
examples with /bin/sh on Solaris 10. To my surprise, some of them
produced errors, and not the output shown in those examples.
I then repeated the experiment with /usr/xpg4/bin/sh, and they
worked as shown in POSIX.
Next, I looked at the manual page for sh:
DESCRIPTION
The /usr/bin/sh utility is a command programming language that executes
commands read from a terminal or a file.
The /usr/xpg4/bin/sh utility is a standards compliant shell. This util-
ity provides all the functionality of ksh(1), except in cases discussed
in ksh(1) where differences in behavior exist.
So, Solaris 10 /bin/sh is not fully in accord with POSIX, and thus
remains the most `primitive' shell that we have to deal with in
practice. I suspect that we'll be running Solaris 10 systems for at
least another five or so years at my site.
I've always found the shell's ${parameterword} expansion
rules hard to remember, and so, instead of
$ x=/one/two/three
$ echo ${x##*/}
three
I normally use
$ basename $x
three
---
- Nelson H. F. BeebeTel: +1 801 581 5254 -
- University of UtahFAX: +1 801 581 4148 -
- Department of Mathematics, 110 LCBInternet e-mail: be...@math.utah.edu -
- 155 S 1400 E RM 233 be...@acm.org be...@computer.org -
- Salt Lake City, UT 84112-0090, USAURL: http://www.math.utah.edu/~beebe/ -
---