Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
. <file> tells bash to source a particular file. What this means is bash basically executes the contents of the other file (there are some complications regarding subshells and the like that sourcing, as opposed to just plain executing, handles, but let's not worry about them at present).
The objective here is to have one set of common set-up commands that get executed for both login and nonlogin shells. For this to happen, we need to put the commands into one file. In my setup, I put all my personal set-up commands in .bashrc. But this is a problem, since then they aren't invoked in login shells. So I add the . ~/.bashrc to my .bash_profile to make .bash_profile run .bashrc and that way, .bashrc gets sourced regardless of whether I'm running a login or nonlogin shell. You could also do it the other way around and have .bashrc source your .bash_profile (where your custom setup commands would be located). Either way will work.
So, to summarize:
-- put your custom setup commands in either .bashrc or .bash_profile
-- have the other file source the file you put your commands into using . <filename>
If this does not work, post the exact errors that you get. Hopefully this helps a little and explains a bit of what's going on.
if [ -f ~/.bash_profile ]; then
. ~ /.bash_profile
fi
in my ~/.bashrc file didn't work.
after altering my user .bashrc as above I logout and try to login again I enter the user name hit enter, enter the password get the " your last login and date..." then "you have mail"
then instead of going to the user prompt I get returned to the original login prompt.
My setup stuff is in ~/.bash_profile which is why I am trying to source it from ~/.bashrc
Can you do 'ls -l ~/.bash_profile .bashrc' then ... if your .bash_profile is a symlink it will not be sourced (because of the if [ -f ~/.bash_profile ] test). This seems unlikely, but worth a check. You can also put an echo statement into each file to see if/when it executes, e.g. in your .bashrc put:
ls -l ~/.bash_profile returns the expected listing
this is my .bashrc file with 2 echos
when attempting to login the first echo "bashrc1 is running" repeats like
an endless loop until it kicks out back to the login prompt???
second echo " bashrc2 is running" doesnt appear at all.
# .bashrc
# User specific aliases and functions
echo "bashrc1 is running"
alias mntusb='sh mntusb.sh'
alias quit='sh quit.sh'
alias reup='sh reup.sh'
# Source global definitions
if [ -r ~/.bash_profile ]; then
. ~/.bash_profile
fi
echo " bashrc2 is running"
Its ok I figured it out .bashrc was sourcing .bash_profile and .bashprofile was sourcing .bashrc
so endless loop once I commented out the sourcing in .bash_profile everything works the way it should although.... the prompt changes from
[xxx@jekyll xxx]#
to
-bash-2.05b$ I can change this using the PS1 or 2 shell variables ?
Originally posted by Warmduvet
Its ok I figured it out :o .bashrc was sourcing .bash_profile and .bashprofile was sourcing .bashrc
so endless loop once I commented out the sourcing in .bash_profile everything works the way it should although....
DOH :)
Quote:
the prompt changes from
[xxx@jekyll xxx]#
to
-bash-2.05b$ I can change this using the PS1 or 2 shell variables ?
Sure you can ... just check where they're being
re-set, too.
Quote:
PPS you get up early Tink :D
Indeed ... ~ 0520 ;)
But I'm home from work ~ 1620, too!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.