Register
It is currently Mon Apr 21, 2014 5:01 am

My which script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Mar 12, 2010 7:54 pm   

Joined: Tue Mar 02, 2010 9:55 pm
Posts: 24
Location: Canada
This is my simple which script...which behaves like the command 'which'

Code:
#! /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


Top
 Profile  
 PostPosted: Sat Mar 13, 2010 8:45 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
Code:
IFS=':'
for path in $PATH
do if [ -f "$path/myfile" ]; then
...


Top
 Profile  
 PostPosted: Sun Mar 14, 2010 3:53 pm   

Joined: Tue Mar 02, 2010 9:55 pm
Posts: 24
Location: Canada
Thanks for the pointers. I reduced my script to this..

Code:
#! /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


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP