On Wed, May 16, 2007 at 08:46:37PM +0000, Tyler Smith wrote: > Hi, > > I've got a question about a short bash script I wrote. I need it to > loop over a number of names, and pass a command to grass that includes > two variations of those names. That was easy. Harder was getting > getting a letter included in each iteration, starting with A for the > first one and going up by one each iteration. What I came up with, > with extra bits snipped, is: > > #!/bin/bash > > lab_num=41 > > for map_name in aest_90 bush_90 carol_90 comp_90 \ > hirs_90 roan_90 swan_90 vir_90 ; > > do > > lab_let=$(echo -n $(printf "\\x$(echo $lab_num)")) > > echo " > $lab_let > $map_name > ${map_name}.ps" ; > > echo $((lab_num++)) > /dev/null ; > > done > > The multi-line echo is passing instructions to a GRASS command, and in > the full script it works fine. This example runs fine without grass as > a demonstration. What I'm wondering about is the line: > > lab_let=$(echo -n $(printf "\\x$(echo $lab_num)")) > > This was the only way I could figure out to loop from A to H. But > since it works on hex escape codes, it won't work past 9. Is there a > cleaner, more general way to do this?
I think there is: #!/bin/bash ( cat <<! A aest_90 B bush_90 C carol_90 D comp_90 E hirs_90 F roan_90 G swan_90 H vir_90 ! ) | while read letter name do printf '%s\n%s\n%s.ps\n\n' "$letter" "$name" "$name" done Hope this helps -- Karl E. Jorgensen [EMAIL PROTECTED] http://www.jorgensen.org.uk/ [EMAIL PROTECTED] http://karl.jorgensen.com ==== Today's fortune: 15% gratuity added for parties over 8.
signature.asc
Description: Digital signature