The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-27-2002
Registered User
 

Join Date: Aug 2002
Posts: 3
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 10:01 AM.
Forum Sponsor
  #2  
Old 08-27-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
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).
__________________
Pete
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0