[Nottingham] bash scripting - gotme

david wolfson eaxdrw at nottingham.ac.uk
Wed Oct 13 11:32:46 BST 2004


Morning!
I've been got by some bash scripting I've been trying to sort out for 
someone in my office, and haven't been able to work out how to get round 
it.  I hoped someone wiser (but not necessarily older ;-)) might be able 
help...

The setup is this; we have another script that does a bunch of image 
analysis, but it needs to run from in the relavant folder.  There a 
quite a few folders, and the aim is to write a script to automate the 
task (i.e. cd into a folder, run the analysis script, cd .., cd into the 
next folder...). So far, we've got the each folder name assigned to 
variable i.e.

$a1=folder1
$a2=folder2
...
$an=foldern

The difficult bit appears to be automatically moving in and out of these 
folders. So far we tried variations on the following:

let i=1
 
        until [ $i -gt $no_of_folders ]; do
 
        folder_var='$'a$line_count                        
        cd $folder_var
        analysis_prog
        cd ..
        i=$(expr $i + 1) 

        done

You'll not be surprised to hear that this doesn't work as it can't find 
a folder called '$a1'.  Clearly the string substitution is not working, 
as it is reading $folder_var as a string, not a variable.  As I say, 
we've tried variations on this, including not using the folder_var 
variable at all, but with the same result. I've sent the lass who's 
needs this off to look at the advance bash scripting sites, but I 
thought it was an interesing (an hopefully simple) one, if anyone out 
there has encountered it before...

I guess the simplified version is; 'how do you get bash to read a string 
as a variable name?'

Thanks for any hints/tips/solutions,

Dave



More information about the Nottingham mailing list