Terminal: Alias trouble

Discussion in 'Mac Apps and Mac App Store' started by cluthz, Oct 17, 2004.

  1. cluthz macrumors 68040

    cluthz

    Joined:
    Jun 15, 2004
    Location:
    Norway
    #1
    I've tried to add many "shortcuts" to the terminal (bash).
    this is what i've done:

    LittleAl:~ tsb$ alias l="ls -la"


    This works great, untill i quit terminal. next time i start the terminal the shortcuts are gone...

    So i want to add these aliases to a config file (where is the bashrc file?? I used to edit it nder linux..)

    Or is it a another way to do this?
     
  2. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #2
    well if you used to edit this in Linux, then you would know the file is called .bashrc and is located in your home directory. If you are running tcsh, then modify your.tcshrc file. If one doesn't exist, create it....
     
  3. cluthz thread starter macrumors 68040

    cluthz

    Joined:
    Jun 15, 2004
    Location:
    Norway
    #3
    i've had no luck with a .bashrc file in my homedirectory,
    but it works if i edit the /etc/bashrc,
    the problem is that this edits all users aliases....
     
  4. Westside guy macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy side of the Pacific NW
    #4
    Please define "I've had no luck with a .bashrc file". Do you mean you've made these additions into a .bashrc file and they haven't worked? Or do you mean you don't see a .bashrc file?

    If #1 - Are you restarting your session afterward? .bashrc will not affect your current session. Also, spaces and single vs. double quotes can matter; so try this:

    alias ls='ls -al'

    If #2 - Create .bashrc with the entries you wish.

    P.S. You are using Panther, I assume?
     
  5. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #5
    .bashrc doesn't work for me either - use .bash_profile or .profile instead.
     
  6. cluthz thread starter macrumors 68040

    cluthz

    Joined:
    Jun 15, 2004
    Location:
    Norway
    #6
    #1 yes i've restarted terminal, and single quotas doesn't work in bash (i think?).. ( i know in tcsh i used >alias l 'ls -la')

    #2 i've created a .bashrc file in my home directory.

    I haven't tried to logout my osx user account, but i have restarted Terminal.app.

    bash is getting the config from the /etc/bashrc, maybe i need to set terminal to point to my /Users/me/.bashrc file
    on redhat you usually point to the /etc/bashrc from you .bashrc
    if [ -f /etc/bashrc ]; then
    . /etc/bashrc # --> Read /etc/bashrc, if present.
    fi
     
  7. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #7
    I'm confused. My bash won't recognize ~/.bashrc for some reason. It sees ~/.profile just fine, though - so I use that instead.
     
  8. cluthz thread starter macrumors 68040

    cluthz

    Joined:
    Jun 15, 2004
    Location:
    Norway
    #8
    So I can add the configs to the .profile instead of the .bashrc file??
     
  9. Westside guy macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy side of the Pacific NW
    #9
    Are you sure you're using bash? The .profile is used by tcsh not bash.

    Please type this and report the answer:

    Code:
    echo $SHELL
    (P.S. cluthz, please answer the "Panther" question because it may matter)

    Edit: I was wrong - .profile is used, but only if .bashrc isn't present. So the wierd question I guess is why isn't it seeing your .bashrc file? BTW .bash_profile won't do the same thing because your terminal session probably is not a login shell.
     
  10. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #10
    Code:
    echo $SHELL
    /bin/bash
    My .profile has a #! /bin/bash at the beginning of it also.

    EDIT: I just changed it to .bash_profile - that also works.
     
  11. Westside guy macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy side of the Pacific NW
    #11
    wrldwzrd89 - it sounds like your terminal session IS a login shell. So unless .bashrc is being invoked from .bash_profile, that could explain why it isn't working to edit .bashrc. Do the following lines (or something similar) exist in .bash_profile?

    Code:
    if [ -f ~/.bashrc ]; then
            . ~/.bashrc
    BASH_ENV=$HOME/.bashrc
    
    The advantage to having stuff in your .bashrc file, as opposed to .bash_profile, is it's invoked for non-login sessions as well.
     
  12. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #12
    Code:
    XXXX:~ yyyy$ cat .bash_profile
    #! /bin/bash
    alias uld=sudo\ /usr/libexec/locate.updatedb
    export PATH="$PATH:/usr/local/bin:/usr/local/sbin"
    computer and user names blacked out for security reasons.
    EDIT: modified my .bash_profile because my little uld alias wasn't working right.
     
  13. Westside guy macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy side of the Pacific NW
    #13
    Okay, that makes sense. You should consider modifying your .bash_profile to also invoke .bashrc. I forgot to close the "if" though:

    Code:
    if [ -f ~/.bashrc ]; then
            . ~/.bashrc
    fi
    
    The BASH_ENV environment variable line I showed in the previous example is probably not required, but it won't hurt either. :D

    On a completely different note: You might want to install anacron, since I noticed you're using a command alias to manually update your locate database. Anacron is a tool to make sure that cron jobs get run, even if you're computer isn't on at the scheduled time (since cron was really designed for servers, which are on 24/7). Anacron can take over management of the "periodic" jobs such as updating the databases for locate etc.
     
  14. cluthz thread starter macrumors 68040

    cluthz

    Joined:
    Jun 15, 2004
    Location:
    Norway
  15. cluthz thread starter macrumors 68040

    cluthz

    Joined:
    Jun 15, 2004
    Location:
    Norway
    #15
    i also have the .profile file in my home directory,
    it only has this line in it..

    . /sw/bin/init.sh
     
  16. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #16
    I don't really need anacron anyway, because my iMac IS running 24/7. What if I want the database updated more often than the scripts update it (which I often do)? What do I do then? That's what the alias is for! My .bash_profile file has been updated with the command to invoke .bashrc - but it currently does nothing since .bashrc does not exist.
     

Share This Page