Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

c shell script

Status
Not open for further replies.

noiz

IS-IT--Management
Apr 19, 2001
17
US
I realize this is a C programing forum, but there seems to be a lack of people who still use the c shell. So hopefully someone here does.

i have the following bourne script that lists all files adn directories in a given file. I have been asked to port it to the c shell and add functionality so that it will ask you to input names of directories and will then return a list of all their files and subdirectories.

My script:
#!/bin/sh
for i in *
do
if [ -d $i ]
then echo "$i is a sub directory"
else
echo "$i is a file "
fi
done

thanks zion
 

echo "Enter Dir name:"
read DIR_NAME
if test -d $DIR_NAME
then
LIST=`ls $DIR_NAME`

for FILE_OR_DIR in $LIST
do
if test -d $FILE_OR_DIR
then
echo "$FILE_OR_DIR is a directory"
else
echo "$FILE_OR_DIR is a file"
fi
done

else
echo "$DIR_NAME is not a directory, bye"
fi
# I did not test it, but it looks simple
#Regards
 

#!/bin/sh
echo "Enter file/dir name: "
read DIR_NAME
flag=0
if [ -d $DIR_NAME ]
then
flag=1
echo "$DIR_NAME is a directory"
elif [ -f $DIR_NAME ]
then
echi "$DIR_NAME is a file"
fi

if [ $flag -eq 1 ]
then
ls $DIR_NAME
fi

This is simple. It is not strictly C shell
syntax since it calls /bin/sh for interpretation.

:cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top