[ale] for in bash using eval

Matt Shade mshade at mindspring.com
Wed Sep 2 13:04:09 EDT 1998


David S. Jackson wrote:
Here are 2 examples for you:
# convert all file names in current directory to lower case
# only operateson plain files - does not change directory names
# will ask for verification befroe overwriting
for x in `ls`
do
        if [ ! -f $x ]; then
                continue
                fi
        lc=`echo $x | tr '[A-Z]' '[a-z]'`
        if [ $lc != $x ]; then
                mv -i $x $lc
                fi
---------------------------
for i in 1 2 3 4 5 6 7 8 9 10
do
  echo $i
done
---------------------------
though that last would be easier written as:
i=1
while [ "$i" -le 10 ]
do
  echo $i
  i=$(($i+1))
done

Matt

 
> Hi,
> 
> I'm plowing through the O'Reilly fishbook (on bash), and the author
> says (on page 187) there's a way to use a for loop with a construct
> similar to FOR i := 1 to 10 ; do or some such (as in Pascal).  He says
> it has to do with variable substitution and the eval statement, but
> I'm sure I don't get it.
> 
> Can anyone help me out here?  He says it's an "advanced usage" and
> that I will be a "true bash hacker" if I can figure it out.  (I think
> I've tried everything that doesn't work!) Are there any wizened bash
> hackers out here who can fill me in?
> 
> --
> David S. Jackson                           http://www.dsj.net
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> My karma ran over your dogma.

-- 
     __        _______________________________
    / /                                       |Matt Shade (RCE)
   / /________  HEWLETT PACKARD COMPANY       |WWARC HP3000 MPE/OS Team
  / /__ / /_ _/ North American Response Center|mss at atl.hp.com
 / / / / /_/ /  20 Perimeter Summit Boulevard |Matt Shade /HP-USA,om41
/_/ /_/ /___/   Atlanta, Georgia  30319 /USA  |Phone: 404/T 648-3076
     / /       _______________________________|Fax:   404/  648-1755
    /_/






More information about the Ale mailing list