How do i add directories to my /bin list?

Discussion in 'Mac Help/Tips' started by FattyMembrane, Sep 13, 2002.

  1. FattyMembrane macrumors 6502a

    FattyMembrane

    Joined:
    Apr 14, 2002
    Location:
    bat country
    #1
    i'm not sure if i phrased the subject correctly, but i just installed packages of lynx and wget, both of which now reside in /usr/local/bin. unfortunately, when i type "user% lynx" into a terminal window it will not run (i've cd'd to the directory and run it from there, which works fine). i know that there's a file somewhere that allows you to add directories to the list of binaries that are immediately available, but i dont know where. i know people probably ask this question all the time, so i appoligize in advance.
     
  2. gbojim macrumors 6502

    Joined:
    Jan 30, 2002
    #2
    You should not be having a problem with this. /usr/local/bin should already be defined as a directory to search for binaries. Try opening the terminal and typing:

    echo $PATH

    In the response that is printed to the screen, you should see /usr/local/bin somewhere.

    Also, you should just be able to enter the command lynx. I'm not sure why you are typing user% first.

    In any case, if you do need to modify the content of the $PATH variable, the file you are looking for is .tcshrc in your home directory. You may have to create this file.
     
  3. FattyMembrane thread starter macrumors 6502a

    FattyMembrane

    Joined:
    Apr 14, 2002
    Location:
    bat country
    #3
    what is the format for specifying directories in the .tcshrc? i created the file with the single line "/usr/local/bin" but still no dice. by "user%" i meant the terminal prompt, not what i typed in. when i ran $PATH i recieved the following output:

    [x63-155:~] metallus% $PATH
    /bin:/sbin:/usr/bin:/usr/sbin: Command not found.

    /usr/local/bin is not in there, so i'm guessing that i need to figure out how to set up the .tcshrc file.
     
  4. peterjhill macrumors 65816

    peterjhill

    Joined:
    Apr 25, 2002
    Location:
    Seattle, WA
    #4
    setenv PATH /dir/i/want/to/add:/another/dir:$PATH

    Here is mine:
    [Titan:~] phill% less .cshrc
    setenv PATH /usr/bin:/usr/sbin:/usr/X11R6/bin:~/bin:/usr/local/bin:/sw/bin:/sw/sbin:/bin:/sbin
    source /sw/bin/init.csh

    I do it all explicitly.
    You could just go with the default plus what you add. Order matters, as that is the precedence for commands with the same name. Make sense?
     
  5. FattyMembrane thread starter macrumors 6502a

    FattyMembrane

    Joined:
    Apr 14, 2002
    Location:
    bat country
    #5
    thanks pete, it worked like a charm. when i went to boot up this morning, this is what i saw:

    Last login: Sat Sep 14 13:50:37 on console
    Welcome to Darwin!
    /usr/local/bin: Permission denied.

    obviously it's reading from the .tschrc file, but will not load it for some reason. all of the permissions are right, but i trashed the .tschrc file and just used the setenv command. everything's honkey dory.
     
  6. macktheknife macrumors 6502a

    macktheknife

    Joined:
    Jan 24, 2002
    #6
    I have a question about how to set a path to an application or script through Terminal. I have read as much as I could on the subject, and I know you can set the path to an app with the following command:

    echo 'setenv PATH /usr/local/bin:$PATH' >> ~/.tcshrc

    However, I want to know *where* this is being written to. Specifically, I am trying to set the path to another directory. I have tried to tinker with the csh.cshrc and csh.login in the /etc/ directory but no luck.

    Can someone please let me know what to do exactly? I know I can set another path via the setenv command, but I want to have more control over.
     
  7. peterjhill macrumors 65816

    peterjhill

    Joined:
    Apr 25, 2002
    Location:
    Seattle, WA
    #7
    The PATH variable is being written to memory. It is not saved anywhere, AFAIK. When your shell starts up, tcsh for example, it loads a default resources file, kind of like a default preferences. I am not sure where it is, since you and I do not want to necessarily edit that file. You are much better off editing your personal ~/.tcshrc file.

    So you know that if you type 'cd' or 'cd ~' that they will take you to your home directly '/Users/yourusername' so ~/.tcshrc is really '/Users/you/.tcshrc

    Hey look what i found by typing 'man tcsh'

    A login shell begins by executing commands from the system
    files /etc/csh.cshrc and /etc/csh.login. It then executes
    commands from files in the user's home directory: first
    ~/.tcshrc (+) or, if ~/.tcshrc is not found, ~/.cshrc,
    then ~/.history (or the value of the histfile shell vari-
    able), then ~/.login, and finally ~/.cshdirs (or the value
    of the dirsfile shell variable) (+). The shell may read
    /etc/csh.login before instead of after /etc/csh.cshrc, and
    ~/.login before instead of after ~/.tcshrc or ~/.cshrc and
    ~/.history, if so compiled; see the version shell vari-
    able. (+)

    Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or
    ~/.cshrc on startup.
     
  8. sparkleytone macrumors 68020

    sparkleytone

    Joined:
    Oct 28, 2001
    Location:
    Greensboro, NC
    #8
    edit your /etc/csh.login file to include the proper directories...

    also, make sure that the environment setting all lies on one line, or else it will not properly load.
     
  9. macktheknife macrumors 6502a

    macktheknife

    Joined:
    Jan 24, 2002
    #9
    After my adventures in Unix shell script tinkering (see the "My TiBook Has Died!" thread), I've decided to find other ways to work around my problem without resorting to tinkering with any login scripts. I am happy to report that I have found a much safer alternative than editing the rc.common or csh.login scripts. Most of you have other suggestions, but I'll post method here for future reference.

    Terminal already recognizes all files in the /usr/local/bin directory (or at least it did for me). So if you want to execute a program from Terminal without specifying the full path, put a simple script named after the program you want to execute. For instance, I would create a simple script in BBEdit and name it "ant" after the program I wanted to execute. The script should have the following code:
    Code:
    #!/bin/sh
    exec /usr/local/ant/jakarta-ant-1.5.1/bin/./ant "$@"
    
    You can change the path in the second line to fit your needs. Then make the file editable:
    Code:
    sudo chmod 755 ant
    
    Then change the permissions on the file:
    Code:
    sudo chown root:wheel ant
    
    The next time you type just "ant" (or whatever you named the script), it should execute the program.

    I personally think this method is safer than editing some login scripts. If you add the wrong path in rc.common or csh.login, your Terminal might not recognize some simple commands like "ls" or "sudo" or, worse, OS X might not boot up at all!
     
  10. macktheknife macrumors 6502a

    macktheknife

    Joined:
    Jan 24, 2002
    #10
    I just want to let anyone who might be searching these forums in the future to know how to find the .tschrc file on your computer. In Terminal, go to your home directory (which should be your default directory when the Terminal starts up) and type "ls -alF" to see all the hidden files. .tschrc should be one of them. To edit this script, type "pico .tschrc" to use pico as the editor. Apparently BBEdit and TextEdit will let you view the file but won't let anyone save changes for files that begin with a period.

    Again, be careful with editing this file: Making the slightest changes in Unix could result in the most devastating consequences.
     

Share This Page