[Nelug] Bash Scripting
Edward Younger - Sun VSP - Firmware Engineer
Edward.Younger at sun.com
Fri Sep 19 11:33:01 UTC 2003
Andrew Hatch writes:
> Wonder if anybody has come across the following:
>
> -----------------------------------
> #!/bin/bash
>
> NUMFILES=3
> FILE1="/home/file1.dat"
> FILE2="/home/file2.dat"
> FILE3="/home/file3.dat"
>
> for i in $(seq $NUMFILES)
> do
> THEFILE=FILE$i
> echo $THEFILE
> done
> ------------------------------------
>
> this will output the following:
>
> FILE1
> FILE2
> FILE3
>
> But what I want it to do is output
>
> /home/file1.dat
> /home/file2.dat
> /home/file3.dat
>
You could use an array to hold the values:
#!/bin/bash
FILES[1]="/home/file1.dat"
FILES[2]="/home/file2.dat"
FILES[3]="/home/file3.dat"
for i in ${FILES[*]}
do
echo $i
done
Eddy.
More information about the Nelug
mailing list