Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cluthz

macrumors 68040
Original poster
Jun 15, 2004
3,118
4
Norway
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?
 
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....
 
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....
 
cluthz said:
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....

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?
 
cluthz said:
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....
.bashrc doesn't work for me either - use .bash_profile or .profile instead.
 
Westside guy said:
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?

#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
 
cluthz said:
#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
I'm confused. My bash won't recognize ~/.bashrc for some reason. It sees ~/.profile just fine, though - so I use that instead.
 
wrldwzrd89 said:
I'm confused. My bash won't recognize ~/.bashrc for some reason. It sees ~/.profile just fine, though - so I use that instead.

So I can add the configs to the .profile instead of the .bashrc file??
 
wrldwzrd89 said:
I'm confused. My bash won't recognize ~/.bashrc for some reason. It sees ~/.profile just fine, though - so I use that instead.

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.
 
Westside guy said:
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)
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.
 
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.
 
Westside guy said:
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.
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.
 
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.
 
i also have the .profile file in my home directory,
it only has this line in it..

. /sw/bin/init.sh
 
Westside guy said:
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.
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.