Shells script problem

Joined
Dec 16, 2006
Messages
33
Reaction score
0
Points
6
Hi Guys

I have a shellscript that is located in my $Home directory, when executed it changes to a directory called "Progs" (/$Home/Progs).

then after user input from myself it searches for another shellscript (there are a few) in that directory and if it doesn't find it it returns an error message.

What I want to achieve is how do i extend my if statement to get it to search in another directory within Progs called Extra (/$Home/Progs/Extra) if the shell script isnt found in Progs and only if the shell script isnt in Extra the script returns an error message.

My if statement looks like this:

echo -n "Enter Command: "

read FILE
FILE=${FILE}".sh"
if [ -f ${FILE} ]; then
./${FILE}
else
echo "File not found."
fi

I've set it up so I don't have to type ./scriptname.sh, only scriptname

Any help would be appreciated :)
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
if [ -f ${file} ]; then
./${file}
elif [ -f ./Extra/${file} ] ; then
./${file}
else
echo "File not found."
fi

or

if [ -f ${file} -o -f ./Extra/${file} ]; then
./${file}
else
echo "File not found."
fi
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top