About trimming a variable
Hi,
When I studied variable or parameter expansions, I learned the following: ${variable%pattern} trim the shortest match from the end ${variable%%pattern} trim the longest match from the end I couldn't figure out the difference between them. Code:
#var1=1100 |
Try:
echo ${var1%0*} echo ${var1%%0*} |
Hi Disillusionist,
Your code example illustrated for me the difference but it violated the trimming purpose. I simply want to trim the leading zeros. eg: 1100 -> 11 , 210 -> 21 Code:
#var1=11001 |
The wildcard * has the bash meaning, not the regexp one. In parameter substitution
Code:
${var%%0*} Code:
$ var=1100 |
All times are GMT -5. The time now is 11:51 AM. |