Computing.Net > Forums > Unix > Korn script help!!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Korn script help!!

Reply to Message Icon

Name: Sterling
Date: April 14, 2003 at 20:46:32 Pacific
OS: Win. XP, Unix
CPU/Ram: Intel Pentium 4, 512MB
Comment:

I'm stumped with this program I'm working on, can someone help. I'm new to UNIX and wanting to learn. The program I'm working on is to:

Write a Korn shell script that will search the UNIX file system of directories for a set of files passed to the script as a set of command line arguments. An example command line of how this script should be exited is:

$ script5 /export/home/studen1 myfile1 myfile2

Where:
script5 -- Name of shell script.
/export/home/studen1 -- Directory in which your search should begin.
myfile1 and myfile2 -- Files you are searching for.

Note that the script must allow for 1 OR MORE file names. This example just happens to show only two.

Instructions
1. When a file is found, the full pathname for the file should be displayed.
2. If a file is not found, no message is necessary.
3. The script should validate the directory entered on the command line and display an error message if the directory was not found.
4. The script must handle one or more file names. The example command line above shows two names, but any number must be supported.
5. The script must validate that at least two arguments have been provided.

Please, no advanced code, I'm not ready for it. Thank you, Sterling



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: April 15, 2003 at 11:48:52 Pacific
Reply:

You'll get more help if you show us the code that you've tried and we'll help you to figure out what is wrong.


0

Response Number 2
Name: Jess Clement
Date: April 16, 2003 at 12:40:02 Pacific
Reply:

This is in ksh:

if [ $# -lt 2 ]
then
echo "Minimum two arguments required"
exit
fi

DIR=$1
ARGS=$#
counter=1

if [ ! -d $DIR ]
then
echo "$DIR invalid directory"
exit
fi

shift

while [ $counter -lt $ARGS ]
do
find $DIR -name $1 -print 2> /dev/null
shift
(( counter = $counter + 1 ))
done


The find command will complain if you don't have permissions to view all directories under the directory you specified as $1.


0

Response Number 3
Name: WilliamRobertson
Date: April 16, 2003 at 16:25:48 Pacific
Reply:

Or for variety:

#!/bin/ksh

function error
{
print -u2 "$*"
exit 1
}

pathname=$1
shift

[[ -d ${pathname} ]] || error "No such directory '${pathname}'."
[[ -x ${pathname} ]] || error "You do not have search permission on directory '${pathname}'."

cd ${pathname}

[[ -z "$*" ]] && error "No filenames specified."

for f in $*
do
[[ -f $f ]] && ls -al $f
done


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Korn script help!!

Changing shell in Korn script www.computing.net/answers/unix/changing-shell-in-korn-script/4747.html

Korn Shell script help please!! www.computing.net/answers/unix/korn-shell-script-help-please/4345.html

Korn shell script help ! www.computing.net/answers/unix/korn-shell-script-help-/7240.html