Computing.Net > Forums > Unix > KSH script problem

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.

KSH script problem

Reply to Message Icon

Name: abby
Date: July 10, 2002 at 08:51:15 Pacific
Comment:

Hi,
I'm trying to prompt the user to supply a path name to a file. Once I read the pathname to a variable in the script, I need to check whether the directory exist or not. If not , then I need to ask the user for reentering the path.
Can anyone show me how to accomplish this ?
Thanks in advance,
abby



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: July 10, 2002 at 09:39:55 Pacific
Reply:

Do a man on 'test'. You'll see that there are numerous flags for testing things like the existence of a directory, a file, a non-zero size file, etc.

This code will loop until a valid path is entered. I'd suggest modifying it to contain a counter, so that it'll exit after 3 failures or somesuch.


validPath=0

while [ $validPath -eq 0 ]
do

echo
echo Please enter the path
read myPath


if [ -d $myPath ]
then

validPath=1
else

echo Sorry, that path is invalid
fi

done

echo
echo $myPath is valid
~


0

Response Number 2
Name: LANkrypt0
Date: July 10, 2002 at 11:42:19 Pacific
Reply:

Just make it a function

Best to make it a function so you can call on it at anytime

#!/bin/ksh
function chkdirectory {
read getdirectory"?Give me Directory> "
if [[ -d $getdirectory ]];then
echo Directory is there!
else
echo Bad Directory
chkdirectory
fi
}
chkdirectory


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


script -entering password... Solaris talking to Intern...



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: KSH script problem

ksh script www.computing.net/answers/unix/ksh-script/6748.html

Waiting problem - KSH script www.computing.net/answers/unix/waiting-problem-ksh-script/7835.html

Need Help With KSH Script www.computing.net/answers/unix/need-help-with-ksh-script/6747.html