This time a short one liner in english, as I think, that this will prove more then useful to other people as well (welcome googlers). In order to optimize a shell script and strip off several unneeded awk calls, I decided to strip trailing zeros from a variable in bash, instead of using the prinft function from awk. So, image the following case:
alex@nashage:~/tmp$ for i in 000123 002423 040000 040404 043253 043403 123456 404040 ; do echo From $i to ${i/*([0])/} ; done
From 000123 to 000123
From 002423 to 002423
From 040000 to 040000
From 040404 to 040404
From 043253 to 043253
From 043403 to 043403
From 123456 to 123456
From 404040 to 404040
alex@nashage:~/tmp$ shopt -s extglob
alex@nashage:~/tmp$ for i in 000123 002423 040000 040404 043253 043403 123456 404040 ; do echo From $i to ${i/*([0])/} ; done
From 000123 to 123
From 002423 to 2423
From 040000 to 40000
From 040404 to 40404
From 043253 to 43253
From 043403 to 43403
From 123456 to 123456
From 404040 to 404040
So actually this trick is pretty simple, once you read it right out of the bash manual... Hope it helps others as well