On Tue, 12 Feb 2002, Cameron Simpson wrote: > On 08:38 12 Feb 2002, Wojtek Pilorz <[EMAIL PROTECTED]> wrote: > | On Tue, 12 Feb 2002, Cameron Simpson wrote: [...] > | > for f in *.pc > | > do newname=`basename "$f" .bc`.jpg > | > mv -i "$f" "$newname" > | > done > | It seems that you try to work correctly for file names containing spaces, > > Yes. > > | etc; if so, the results of basename should be protected > | from word split (I am also correcting mistyped ".bc") > > No. > > The bit after the = takes place _after_ word split.
You are right, I was overzealous in quoting everything. Thank you for correcting me and sorry for the confusion. > > So, for example, these are _perfectly_ safe: > > a="1 2 3" > b="this;that" > c=`ls` > abc=$a$b$c > > | for f in *.pc; do newname="`basename "$f" .pc`".jpg; > > This extra "`...`" is unnecessary, and makes it harder to use \ inside the `...`. > > | > Of course that works in any Bourne shell, not just bash. Which is as it should >be. > | > | If we want bash-only solution we can use a bit faster (no subprocessed > | created): > | > | for f in *.pc; do newname="${f%.pc}".jpg; mv -i "$f" "$newname"; done > > True, and will fail badly on a system without bash. (And again, you don't This should work with Korn shell also; > need those extra "" around ${f%.pc}.) True, now I know. > > Unless speed is actually a problem, portability is generally to be preferred. For scripts - surely, unless there is a lot of iterations (e.g. on my system (PII, 450 MHz, 128MB RAM, RedHat Linux 6.2) the times savings by doing all in bash are often significant: $ time bash2 -c 'x=0; while test $x -le 3000; do x=`expr $x + 1`; done' real 0m18.734s user 0m9.080s sys 0m9.660s (bash1 is a bit faster but sometimes fails in the middle with "Can't reopen pipe to command substitution" error message) $ time bash2 -c 'x=0; while test $x -le 3000; do x=$(($x+1)); done' real 0m0.572s user 0m0.540s sys 0m0.030s For typing commands on my systems where bash is always installed I personally find bash-specific constructs very convenient; I also use bash-specific constructs in my scripts which run on systems I know contain bash; The speed difference is esp. noticable on underpowered boxes (not enough RAM, etc) or on systems with slow process creation (e.g. Windows 2000 with cygwin (on Pentium 150MHz with Win2K and cygwin 100 iterations with expr take more than 30 seconds, 100 iterations of bash-only loop half a second)). > > Cheers, > -- > Cameron Simpson, DoD#743 [EMAIL PROTECTED] http://www.zip.com.au/~cs/ > > You can't always get what you want. - The Rolling Stones > Best regards, Wojtek _______________________________________________ Redhat-list mailing list [EMAIL PROTECTED] https://listman.redhat.com/mailman/listinfo/redhat-list