Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > invoking unix apps from cmd line

invoking unix apps from cmd line
Thread Tools
Mac Elite
Join Date: Oct 2001
Location: Internet
Status: Offline
Reply With Quote
Jul 24, 2003, 08:47 PM
 
I just installed netcat and I am a bit confused. I thought that I could invoke netcat regardless of what directory I was in by typing netcat or nc (just like I can with top, or whoami etc.). Instead I need to "cd" to the directory that netcat is stored and invoke it with "./nc". I have had this problem with other apps that I have installed like hugs98 (a haskell interpreter). I always had to do a dot-slash (./) before the application name for it to run. What am I doing wrong? how can I get these apps to run like a normal unix app (ie without the ./ prefix), regardless of the directory I am currently in...??!!


MacBook Air 11" 1.6Ghz 4GB 128GB Backlit Keyboard, 4S, iPad 2
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 24, 2003, 08:58 PM
 
Originally posted by hadocon:
how can I get these apps to run like a normal unix app (ie without the ./ prefix), regardless of the directory I am currently in...??!!

Add the directory containing the app to your PATH environment variable.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status: Offline
Reply With Quote
Jul 24, 2003, 09:28 PM
 
Originally posted by hadocon:
I just installed netcat and I am a bit confused. I thought that I could invoke netcat regardless of what directory I was in by typing netcat or nc (just like I can with top, or whoami etc.). Instead I need to "cd" to the directory that netcat is stored and invoke it with "./nc". I have had this problem with other apps that I have installed like hugs98 (a haskell interpreter). I always had to do a dot-slash (./) before the application name for it to run. What am I doing wrong? how can I get these apps to run like a normal unix app (ie without the ./ prefix), regardless of the directory I am currently in...??!!

They ARE running like "normal Unix apps" (whatever that is). Your particular problem is that the new apps are not in your normal Unix path. Do this:

echo $PATH

On my system I get:

[cider:~] physicst% echo $PATH
/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin

...the system looks for an executable (or app), from left to right, in the listed folders. Your PATH may look different from mine. If the new apps are located, say, in /usr/local/bin (very very common)... then my system will not "see" them when I type their name at the command prompt. It will ONLY look in the folders listed in the PATH.

There are several ways around the problem but I will only list one of them because, in my opinion, it is the correct way to do it.

One way to fix it is to extend your PATH so that the folder the new apps are in is included. The usual place for non-standard apps is /usr/local/bin and/or /usr/local/sbin. When I say non-standard I mean ones that are not installed as regular Mac OS X packages or come with the install from Apple. You can do this by editing the file /etc/csh.login It should look like this:

setenv PATH "/bin:/sbin:/usr/bin:/usr/sbin"

add (within the "") /usr/local/bin and /usr/local/sbin so that it looks like this:

setenv PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"

save it. Then type at the prompt:

source /etc/csh.login
echo $PATH

You should now see the full PATH including the entries you just made. Extending the PATH in the /etc/csh.login file will do it for all users by default on your system. It will also load up automatically each time you log in.

If the new apps you are adding are NOT in one of the "standard" folders... and not in any of the new folders you added to the PATH then either copy them to /usr/local/bin or make softlinks to them there.

If any of the above isn't clear please ask.
-DU-...etc...
     
hadocon  (op)
Mac Elite
Join Date: Oct 2001
Location: Internet
Status: Offline
Reply With Quote
Jul 25, 2003, 10:01 AM
 
Worked like a charm. Thanx!


MacBook Air 11" 1.6Ghz 4GB 128GB Backlit Keyboard, 4S, iPad 2
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:22 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2