RSS Forums RSS
Please support our Shell Scripting advertiser: Programming Forums

101 scripting questions

Join Date: Apr 2008
Posts: 53
Reputation: omrsafetyo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 9
omrsafetyo omrsafetyo is offline Offline
Junior Poster in Training

Re: 101 scripting questions

  #2  
Jun 27th, 2008
In order just to type the name of the file to execute, it needs to be in an executable directory - so for e.g. if you have a script that is used frequently, drop it in /usr/local/bin and it will become executable from anywhere. You can also add the current directory as an executable path with:
[code]
PATH=${PATH}PWD
[code]
However, please note that this can be extremely dangerous - because then any script in the current directory can accidentally be run.

I'm not quite sure what your second question is getting at. It sounds like you are trying to recreate the "which" command.

If you type which ls it will tell you which ls your local environment executes.

$ which ls
/bin/ls

In order to recreate this, you would have to delimit the user's path variable:

command=$1
for path in `echo $PATH | sed "s/:/ /g"`
do
   ls $path | grep $command
done
Unlike which, this will return all installed instances (in your path) - the which command will only return the first instance found, which is the program that would actually be executed on your system.
Last edited by omrsafetyo : Jun 27th, 2008 at 11:56 pm.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:02 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC