Can anyone help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Can anyone help
# 1  
Old 08-27-2002
Can anyone help

This is how far I have got, but it still doesnt do what it is supposed to

The code is to be written on KornShell and has to be done command line and
menu form, im trying to do the menu code first
then the command line will be simpler.

The question is:

for each file in the directory <dir_name>, display its name, together with
the word file if it is a normal file,
dir if it is a directory or other if it is neither a normal file nor a
directory, and the word readable if the file is readable by
the current user. For example, a typical output might be:

fool.c file readable
foo2.c file
foo3 other readable
progs dir readable

finfo
Code:
while getopts :t args

do
	case $args in
	
	t) print "t option: data: $OPTARG";;
	
	
	esac
	
done

((pos = OPTIND -1))
shift $pos

PS3='option> '

if (( $# == 0 ))
then if (( $OPTIND == 1 ))
then select menu_list in dirinfo exit

do case $menu_list in

###################################################################################################

	dirinfo) 
	
	print "***************************************************************************";
	print "* This option shows the different files in a directory and its attributes *";
	print "***************************************************************************";
	print "";
	print "Enter the directory name";
	print "";
	
	read dir_name;	
	
	if test -d $dir_name
	
	then 
		
	cd $dir_name

	ls -1 
	
	else
		
		print ""
		print "The name you have entered is not a directory."
		print ""
	
	fi;
	
	print ""
	print "Hit enter to continue"
	read junk;;
	
###################################################################################################
	
	exit) exit;;
	
	*) print "unknown option";;
	
	esac
	
	done
	
	fi
	
	else print "extra args??: $@"

fi

inserted code tags for readability --oombera

Last edited by oombera; 02-16-2004 at 01:01 PM..
# 2  
Old 08-28-2002
You haven't said which part isn't working or what the problem is...but this will do the file type stuff for you....

Code:
#!/bin/ksh
#
print "Please enter a directory name and path:"
read the_dir
cd $the_dir
for y in *
do
if [ -d $y ];then
if [ -r $y ];then ( echo "$y is a readable directory" )
else ( echo "$y is a non-readable directory")
fi
#
elif [ -f $y ];then
if [ -r $y ];then ( echo "$y is a readable file")
else ( echo "$y is a non-readable file")
fi
#
elif [ -r $y ];then ( echo "$y is a readable OTHER file")
else ( echo "$y is a non-readable OTHER file")
fi
done


You could customise the echo statements obviously but this will do what you have requested (not menu based though).
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question