bash scripting question
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?
Thanks,
Tyler
Reply to: