Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
On 06/10/2015 06:29 AM, Eric Blake wrote:
>> http://stackoverflow.com/questions/8223170/bash-extracting-last-two-dirs-for-a-pathname
>
> Please try harder to make your questions self-contained. Making people
> chase down a URL is not as nice as directly pasting the code in question:
>>
>> DIRNAME = /a/b/c/d/e
>>
>> I'd like:
>>
>> DIRNAME2 = d/e
>
Also, be aware that the constructs listed on that site are NOT robust to
all pathnames:
> DIRNAME2=$(basename $(dirname $DIRNAME))/$(basename $DIRNAME)
is improperly quoted (and therefore mishandles directory names
containing space), is not properly using -- to denote end of options
(and therefore mishandles a directory name that starts with -), and is
using command substitution on data that might end in a significant
newline (and therefore mishandles a directory name that ends in
newline). Furthermore, it mishandles the case when $DIRNAME is // on
platforms where // is distinct from / (where the correct answer should
be "//", not "/////").
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc Description: OpenPGP digital signature