On 14:13 12 Feb 2002, Wojtek Pilorz <[EMAIL PROTECTED]> wrote: | > | 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;
Ah. Then it's more portable than I thought. Since the ksh is the basis for the POSIX shell, /bin/sh on almost all modern systems should support this then. | > 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 [... versus ...] | $ time bash2 -c 'x=0; while test $x -le 3000; do x=$(($x+1)); done' | real 0m0.572s | user 0m0.540s | sys 0m0.030s Yeah, but this is a slightly contrived example. This script is basicly doing _only_ arithmetic. The shell is the wrong tool for that. If it were doing something else as well the penalty of using expr would be (comparatively) smaller i.e. the same absolute cost, but a much smaller proportion of the total runtime. There are other ways to do this kind of thing. For example: seq 1 3000 | while read x; do something with $x; done Of course, seq is a GNU tool, but it's very handy. Without seq, maybe: awk 'END { for (i=1; i<=3000; i++) {print i; }}' </dev/null \ | while read x; do something with $x; done The core issue here is to offload the arithmetic to something else than the shell. | 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)). But your pain must be very great when using a system without bash... Cheers, -- Cameron Simpson, DoD#743 [EMAIL PROTECTED] http://www.zip.com.au/~cs/ Hello, my name is Yog-Sothoth, and I'll be your eldritch horror today. - Heather Keith <[EMAIL PROTECTED]> _______________________________________________ Redhat-list mailing list [EMAIL PROTECTED] https://listman.redhat.com/mailman/listinfo/redhat-list