[Nottingham] Bash: test "file exists" - gotme again

Ted ted at nowtsfree.freeserve.co.uk
Thu Oct 14 17:45:07 BST 2004

Hi Dave,
    I've been watching this thread and the previous bash scripts
and thinking that it might be simpler to put the directory names
into a file and feed that on the standard input to your script.
Then you wont need to change the script to add new directories.

i.e. here's the_script:

| while read dir; do
| 	cd $dir
| 	echo "Processing directory $dir"
| 	for f in *.tif; do
| 		echo "Processing file $f"
| 	done
| 	cd ..
| done

You could generate the list of directories with an editor, or with
something like

  ls > /tmp/dirs

then run the_script with the file of directory names on stdin

  the_script < /tmp/dirs > /tmp/log 2>&1

Gotchas: unix already has programs called script and test.
... well they often catch me out anyway. Have fun!

Ted <ted at nowtsfree.freeserve.co.uk>

More information about the Nottingham mailing list