Arguements with a shell script [Archive] - C Board

PDA

View Full Version : Arguements with a shell script


Doh
11-27-2002, 08:57 PM
I have to write a shell script that copies all files in the directory subtree and output the files into one file, and all directories into another file.

The arguement passed is the directory my script should start in. I have this, but don't know how to set the arguement and make the script not crash. I know the arguement is stored in '$1' but I dunno where to add "cd $1" or something in this code.


#!/bin/sh
for i in *; do
if test -f $i; then
echo `pwd`/$i >> /gaul/s1/student/2001/rgallard/outfiles.txt
fi
done
for k in *; do
if test -d $k; then

echo `pwd`/$k >> /gaul/s1/student/2001/rgallard/outdirs.txt
cd $k

/gaul/s1/student/2001/rgallard/prt4.sh
cd ..

fi
done

Unreg
11-28-2002, 02:20 PM
Lookup the find command, and let that do the work for you.

EG

To print all directories under root:

find / -type d