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 > macOS > Adding commands/scripts

Adding commands/scripts
Thread Tools
Tom C
Junior Member
Join Date: May 2001
Status: Offline
Reply With Quote
Apr 30, 2003, 11:14 AM
 
I have some scripts that I want to run from the command line without having to type out the full path. In which folder should I put them, and how do I get tsch to recognize them as commands?
     
Rainy Day
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Apr 30, 2003, 01:23 PM
 
I have some scripts that I want to run from the command line without having to type out the full path. In which folder should I put them,
Do echo $path This shows you the directories which are searched every time you issue a command. If a script is found in one of these directories, it is executed. Directories are searched in order listed; only the first script found will be executed.

Note: Usually, the last entry is . (dot). This signifies the current working directory. This means that if the script is not found in any of the explicitly named directories, the current working directory is also searched. This may be all you need, depending on your application. Certainly it is useful for debugging scripts, at any rate.

If none of these directories are acceptable to you, you may append a directory to the path variable (see man set for more info on how to do this). Tip: You'll probably want to do this from a startup file.

and how do I get tsch to recognize them as commands?
You need to turn on the execute permission for the script. A chmod u+x scriptFileName should do it.
     
Tom C  (op)
Junior Member
Join Date: May 2001
Status: Offline
Reply With Quote
Apr 30, 2003, 02:14 PM
 
If none of these directories are acceptable to you, you may append a directory to the path variable (see man set for more info on how to do this). Tip: You'll probably want to do this from a startup file.
1. Is there any standard directory for putting your own scripts?

2. I put the command in .tschrc. Is this the appropriate startup file?

3. I couldn't figure out how to append to the variable with the set command. How do you do this? (Everything works fine when I manually retype the entire current contents of path and then my additions.)

You need to turn on the execute permission for the script. A chmod u+x scriptFileName should do it. [/B]
I already did this. What confused me was that the script worked fine if I typed the full path name, but if I was in the directory where the script was located, simply typing the script name did not execute the script. It turns out that the default value of path did not include "."
     
Rainy Day
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Apr 30, 2003, 03:14 PM
 
1. Is there any standard directory for putting your own scripts?
The first directory listed in the PATH variable is probably the one you'll want to use (the directory may not exist and you may have to create it). Here is what my path variable looks like:

path (/Users/username/bin /usr/local/lib /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin /sbin /usr/lib /Developer/Tools .)

2. I put the command in .tschrc. Is this the appropriate startup file?
I don't use tcsh shell and can never remember which of the two billion startup files it has is the appropriate one for what. You'll have to look at man tcsh for that, or wait for someone else to answer the question.

3. I couldn't figure out how to append to the variable with the set command. How do you do this? (Everything works fine when I manually retype the entire current contents of path and then my additions.)
Well, tcsh does it differently from bash (my preferred shell) and i'm not sure of the exact syntax. Generally, it involves resetting the variable to a value which includes its old value, plus a new constant, such as "${path} /Users/username/someOtherDir".

Alternatively, you could find which of the startup files defines the variable in the first place, and modify that (or copy it, or whatever).

Personally, i think you're better off not tweaking the variable if you can avoid it.

I already did this. What confused me was that the script worked fine if I typed the full path name, but if I was in the directory where the script was located, simply typing the script name did not execute the script. It turns out that the default value of path did not include "."
Of course another option is to create an alias which specifies the full path name. I'm not recommending you do this, mind you, but it is an option.

Personally, i think the best solution is just to put your script in the first directory (which is in your user space) in the default setting of the path variable (e.g. /Users/username/bin). Again, you may have to create this directory.
     
   
 
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
Top
Privacy Policy
All times are GMT -4. The time now is 10:17 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,