I am trying to loop through lots and lots of folders and use the names of the folders to run a Python script which has parameters.
E.g.
-- setup_refs -n John -f England/London/Hackney/John -c con/con.cnf
Normally to run `setup_refs` once from command line it's: `python setup_refs.py -n John -f England/London/Hackney/ref -c con/con.cnf`
The program folder (/home/program/) contains:
setup.refs.py (script)
ref (folder)
con (folder) - con.cnf (file)
cd /home/program/ ;
for fldr in /home/program/ref/* ; do
echo "Setting up ---> $fldr" ;
basenm=${fldr##*/} ; new_fldr=${basenm%%_*} ;
python /home/program/setup_refs.py -f "$new_$fldr" -n /home/program/ref/"$new_$fldr" -c /home/program/config/config.cnf ;
echo "$fldr setup complete" ;
done
echo "Automated setup complete." ;
Observations:
You use the -n and -f switches inconsistently in the code compared to your example.
In your code you use /home/program/config/config.cnf rather than your required con/con.cnf
You don't need the trailing semicolons at the end of each line in bash or other bourne-derived shellscripts.
If you use:
cd /home/program/ref
for fldr in *
you don't need the extra step of removing the directory part of the filename. You will, however be in a different directory than the one you start out in (this may be a problem, but you are using full pathnames anyway).
Stupid question: In the above code if there is a folder (file?) named john_smith your code will set the $new_fldr variable to john. What happens to a folder named john?
Another stupid question: Have you tried running that code?