All Scripts go here. In progress, finished, etc.
by G4143 » Fri Mar 12, 2010 7:54 pm
This is my simple which script...which behaves like the command 'which'
- Code: Select all
#! /bin/sh
echo -n "enter file to find->"
read myfile
fslash="/"
IFS=":"
set $PATH
for p in $*
do
if ls "$p${fslash}${myfile}" > /dev/null 2>&1
then
echo -n "The file '$myfile' exists in-> "
echo $p${fslash}${myfile}
exit 0
fi
done
echo "'$myfile' does not exist"
exit 1
-
G4143
-
- Posts: 24
- Joined: Tue Mar 02, 2010 9:55 pm
- Location: Canada
by Watael » Sat Mar 13, 2010 8:45 pm
- Code: Select all
IFS=':'
for path in $PATH
do if [ -f "$path/myfile" ]; then
...
-
Watael
-
- Posts: 232
- Joined: Mon Mar 02, 2009 3:03 am
by G4143 » Sun Mar 14, 2010 3:53 pm
Thanks for the pointers. I reduced my script to this..
- Code: Select all
#! /bin/sh
echo -n "enter filename->"
read mycomm
IFS=":"
for i in $PATH
do
if [ -f "${i}/$mycomm" ]
then
echo ${i}/$mycomm
exit 0
fi
done
echo "'$mycomm' not found!"
exit 1
-
G4143
-
- Posts: 24
- Joined: Tue Mar 02, 2010 9:55 pm
- Location: Canada
Return to The Sandbox
Who is online
Users browsing this forum: No registered users and 1 guest