Actually I'm not getting any difference whether or not I put the 'xxx' part is there in the expr section.
I made these 3 files:
F ILE1 FIL -E2 fIlE3
Now I run the script given in that link (last line is replaced with echo instead of mv):
Code:
bash-2.05b ~/scrap$ for f in *; do
> g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`
> echo $g
> done
f ile1
fil -e2
file3
And now if I remove the 3 x's in line 2:
Code:
bash-2.05b ~/scrap$ for f in *; do
> g=`expr "$f" : '\(.*\)' | tr '[A-Z]' '[a-z]'`
> echo $g
> done
f ile1
fil -e2
file3
Its the same!
This link gives the same example and seems to imply that this usage of expr can handle control characters and whitespace better than simpler scripts. I'm guessing that's what the xxx is for. Apart from that the explanation is fairly simple I guess.
Code:
g=`expr "$f" : '\(.*\)' | tr '[A-Z]' '[a-z]'`
expr "$f" : '\(.*\)' This part saves the entire value of $f. Usual regex stuff here.
| tr '[A-Z]' '[a-z]'... and passes it to the tr commands which changes the case.
So maybe someone else here knows how prefixing 'xxx' in the regex helps.