简体   繁体   中英

bash parameter expansion not working as expected

The below example is from one of the many web pages I consulted. I cannot get the "remove from beginning till marker" or "remove from marker till end" to work, perhaps something is wrong with how I specify the pattern? The final goal is to remove everything from a line of text, from a given marker till the end. A solution with sed might well be found too but this one annoys me.

VERSION=0.11.3-issue#18.6a0b43d.123
# this one works as expected
echo ${VERSION/\#/}
0.11.3-issue18.6a0b43d.123
# all the others don't, they return the input unchanged
# trying to remove the 'i' to get the syntax straight
echo ${VERSION%i}
0.11.3-issue#18.6a0b43d.123
echo ${VERSION%\i}
0.11.3-issue#18.6a0b43d.123
${VERSION%%\i}
0.11.3-issue#18.6a0b43d.123
echo ${VERSION%%i}
0.11.3-issue#18.6a0b43d.123

The problem is that the thing after # or % isn't a marker, but a pattern.

echo ${VERSION%i*}

Add asterisks to match the rest of the value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM