![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 Last edited by oombera; 02-16-2004 at 10:01 AM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 |