Hi,
I'm not sure this is a bug or a misunderstanding by me, but it sure
surprised me:
$ set -- file.txt txt
$ printf 'Two values: %s %s\n' "$1" "$2"
Two values: file.txt txt
$ printf 'First value with suffix removed: %s\n' "${1%.*}"
First value with suffix removed: file
$ printf 'First value with second value removed from end: %s\n' "${1%.$2}"
First value with second value removed from end: txt
I would have expected the last two parameter expansion to generate the
same result ("file"). Also, removing the dot ("${1%$2}") generates an
empty result.
Note that using variables, this works as expected:
$ filename=file.txt
$ suffix=txt
$ printf 'First value with second value removed from end: %s\n'
"${filename%.$suffix}"
First value with second value removed from end: file
This is on a current system using either /bin/sh or /bin/ksh and the
effect of trying to remove from the start of the string is similar.
Regards,
--
Andreas Kusalananda Kähäri,
National Bioinformatics Infrastructure Sweden (NBIS),
Uppsala University, Sweden.
När du har kontakt med oss på Uppsala universitet med e-post så innebär det att
vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du
läsa här: http://www.uu.se/om-uu/dataskydd-personuppgifter/
E-mailing Uppsala University means that we will process your personal data. For
more information on how this is performed, please read here:
http://www.uu.se/om-uu/dataskydd-personuppgifter/