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 > Do aliases belong in .bashrc or .profile?

Do aliases belong in .bashrc or .profile?
Thread Tools
mqymouse
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Oakland, CA, USA
Status: Offline
Reply With Quote
May 30, 2004, 07:17 PM
 
I'm very new to all of this, so bear with me.

I have read in two different places two different things to do with your aliases in the bash shell. One says to put your aliases in the .profile. The other source indicates that all aliases belong in the ~/.bashrc file instead.

So, I've added my aliases to ~/.bashrc, and they don't work.

I've copied the same aliases to the .profile, and they work as directed. But I thought that .profile was for higher level commands, not user-specific commands.

Is this proper? Which source is correct? Or does it really matter as long as it works?

On an unrelated note, is there a bash equivalent to the rehash command from csh shells?

Thanks,
Michael
Le ver vert va vers le verre vert.
     
mqymouse  (op)
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Oakland, CA, USA
Status: Offline
Reply With Quote
May 30, 2004, 08:19 PM
 
Further digging has discovered a bashrc file in the /etc directory. Does this file conflict with the ~/.bashrc file?
Le ver vert va vers le verre vert.
     
mqymouse  (op)
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Oakland, CA, USA
Status: Offline
Reply With Quote
May 30, 2004, 09:28 PM
 
Today is a day of exploration:

I ran ps, and it showed me

Code:
PID TT STAT TIME COMMAND 421 p1 Ss+ 0:00.07 bash 1321 std S 0:00.50 -bash
Does this mean there are two shells running?
Le ver vert va vers le verre vert.
     
suthercd
Senior User
Join Date: Oct 2000
Location: Midwest
Status: Offline
Reply With Quote
May 31, 2004, 01:24 PM
 
mgymouse-

When you create a .bashrc file in your home directory, that is read instead of the /etc/bashrc file.

Using the Terminal, you are in a non-login interactive shell. Each Terminal window you opens is another of the same type of shell. These read .bashrc if it is present, /etc/bashrc if it is not.

~/.bash_profile, .bash_login, and .profile are looked for, in that order, when a bash login shell is started. When the first of the three is found, it is read and bash stops looking. A login interactive shell is an authenticated shell and this type of shell is used by the system for a variety of housekeeping, setup, configuration tasks. When you login to OS X, a login shell is started and the first of there files is read.

Here is my .bash_profile
Code:
export ANT_HOME=/usr/local/ant/apache-ant-1.6.1 export CATALINA_HOME=/Library/Tomcat export JAVA_HOME=/Library/Java/Home export CVSROOT=/usr/local/cvsrep export PYTHONPATH=/Users/xxx/bin/py export PATH=$PATH:/usr/local/mysql/bin:/usr/local/bin:/Library/Tcl/bin:/Users/xxx/bin PS1="\W $" . .bashrc
You see the last line calls my .bashrc file. All of my path info is available to the system.

My .bashrc file
Code:
PROMPT_COMMAND='echo -ne "\033]0;${PWD/$HOME/~}\007"' alias path='echo -e ${PATH//:/\\n}' alias prj='cd /Volumes/Data/Projects' alias lm='ls -la | more' alias lt='ls -atrl | more' alias ..='cd ..' alias /='cd /' alias dsk='cd ~/Desktop' alias lcl='cd /usr/local' alias jvd='cd ~/Documents/Java_code' alias jvr='cd ~/Documents/Java_code/JavaRanch' alias ls='ls -G' shopt -s histappend shopt -s cdspell shopt -s cdable_vars
Info here is what I have set up for use in the Terminal or with X11.

OSXFAQ has a great multi part OS X Unix tutorial that is very comprehensive and one I that really helped me.

HTH
Craig
     
Kristoff
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
May 31, 2004, 01:37 PM
 
hnmmm.... I use TCSH and Fred Sanchez's method of setting that stuff, so mine are in:

~/Library/init/tcsh/aliases.mine

and the env vars go in:

~/Library/init/tcsh/environment.mine
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
mqymouse  (op)
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Oakland, CA, USA
Status: Offline
Reply With Quote
May 31, 2004, 04:02 PM
 
Thanks for the advice. I followed your instructions for the .bash_profile which passes on to the .bashrc and it all works well for me. I'll forego the .profile and using the /etc/bashrc file to set aliases.

I'm learning very slowly, but it's all really cool.

Thank you for your help,
Michael
Le ver vert va vers le verre vert.
     
suthercd
Senior User
Join Date: Oct 2000
Location: Midwest
Status: Offline
Reply With Quote
Jun 1, 2004, 04:27 PM
 
Good the hear. Just to clarify, if you create ~/.profile (or .~/bash_profile or ~/bash_input) the default /etc/profile will not be read by bash. You can enter 'cat /etc/profile' to list the contents of that file and use that to make certain you have are aware of the PATH info etc. that was included in the default file.

Craig
     
   
 
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 01:37 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.,