bashrc or bash_profile? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Hide current working directory in terminalUnderstanding .bashrc and .bash_profileHow can I get tab-completion in the interactive Python interpreter?What is the correct way to run a command after boot on ubuntu 18.04?scp 33H messageExporting bash function in .profile or .xprofile kills X during loginHow can my script determine whether it's being run by bash or dash?Why ~/.bash_profile is not getting sourced when opening a terminal?Understanding .bashrc and .bash_profileWhat is the $BASH_COMMAND variable good for?Why isn't .profile sourced when opening a terminal?Install software that uses a different shell. ~/.bash_profile`exec /bin/bash -il` fails in .profileUnderstanding Bash Script Order

Does surprise arrest existing movement?

Why is "Consequences inflicted." not a sentence?

I am not a queen, who am I?

When to stop saving and start investing?

Why did the IBM 650 use bi-quinary?

If a contract sometimes uses the wrong name, is it still valid?

Why is black pepper both grey and black?

What makes black pepper strong or mild?

What is this single-engine low-wing propeller plane?

What are the motives behind Cersei's orders given to Bronn?

Can a non-EU citizen traveling with me come with me through the EU passport line?

How do I keep my slimes from escaping their pens?

Is high blood pressure ever a symptom attributable solely to dehydration?

What is the correct way to use the pinch test for dehydration?

How can I fade player when goes inside or outside of the area?

Do you forfeit tax refunds/credits if you aren't required to and don't file by April 15?

IndentationError when pasting code in Python 3 interpreter mode

Is there a concise way to say "all of the X, one of each"?

How can I make names more distinctive without making them longer?

Should I call the interviewer directly, if HR aren't responding?

Should gear shift center itself while in neutral?

Gastric acid as a weapon

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

What LEGO pieces have "real-world" functionality?



bashrc or bash_profile?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Hide current working directory in terminalUnderstanding .bashrc and .bash_profileHow can I get tab-completion in the interactive Python interpreter?What is the correct way to run a command after boot on ubuntu 18.04?scp 33H messageExporting bash function in .profile or .xprofile kills X during loginHow can my script determine whether it's being run by bash or dash?Why ~/.bash_profile is not getting sourced when opening a terminal?Understanding .bashrc and .bash_profileWhat is the $BASH_COMMAND variable good for?Why isn't .profile sourced when opening a terminal?Install software that uses a different shell. ~/.bash_profile`exec /bin/bash -il` fails in .profileUnderstanding Bash Script Order



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








49















I know the difference between the two bash login scripts:



.bashrc is run only by "non-login" shells.



.bash_profile (or .bash_login or .profile) is executed by "login" shells.



Does anyone have some good examples of what things that are a better fit for login-only execution, such that I'd only put them in .bash_profile, but they wouldn't really make sense in .bashrc?



(I know most of us source .bashrc out of .bash_profile, so there doesn't seem to be much point in the opposite question...)










share|improve this question



















  • 3





    See also the same question at Super User.

    – Gilles
    Sep 6 '10 at 19:41

















49















I know the difference between the two bash login scripts:



.bashrc is run only by "non-login" shells.



.bash_profile (or .bash_login or .profile) is executed by "login" shells.



Does anyone have some good examples of what things that are a better fit for login-only execution, such that I'd only put them in .bash_profile, but they wouldn't really make sense in .bashrc?



(I know most of us source .bashrc out of .bash_profile, so there doesn't seem to be much point in the opposite question...)










share|improve this question



















  • 3





    See also the same question at Super User.

    – Gilles
    Sep 6 '10 at 19:41













49












49








49


13






I know the difference between the two bash login scripts:



.bashrc is run only by "non-login" shells.



.bash_profile (or .bash_login or .profile) is executed by "login" shells.



Does anyone have some good examples of what things that are a better fit for login-only execution, such that I'd only put them in .bash_profile, but they wouldn't really make sense in .bashrc?



(I know most of us source .bashrc out of .bash_profile, so there doesn't seem to be much point in the opposite question...)










share|improve this question
















I know the difference between the two bash login scripts:



.bashrc is run only by "non-login" shells.



.bash_profile (or .bash_login or .profile) is executed by "login" shells.



Does anyone have some good examples of what things that are a better fit for login-only execution, such that I'd only put them in .bash_profile, but they wouldn't really make sense in .bashrc?



(I know most of us source .bashrc out of .bash_profile, so there doesn't seem to be much point in the opposite question...)







scripts startup bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago









Kevin Bowen

14.9k155971




14.9k155971










asked Aug 7 '10 at 2:14









Don FaulknerDon Faulkner

6451613




6451613







  • 3





    See also the same question at Super User.

    – Gilles
    Sep 6 '10 at 19:41












  • 3





    See also the same question at Super User.

    – Gilles
    Sep 6 '10 at 19:41







3




3





See also the same question at Super User.

– Gilles
Sep 6 '10 at 19:41





See also the same question at Super User.

– Gilles
Sep 6 '10 at 19:41










2 Answers
2






active

oldest

votes


















24














Since a .bashrc is for non-login shells, I avoid any commands which echo to the screen. I've also run into experiences where echo statements in .bashrc will cause sftp and rsync commands to fail (and maybe scp commands as well).



# Print some information as we log in
# -s: OS Name -n: Node name -r: OS Release
uname -snr
uptime


Also, you generally won't run ssh-agent from a non-interactive shell. So I have this in .bash_profile.



if [ -f ~/.ssh/ssh-agent ]; then . ~/.ssh/ssh-agent; fi





share|improve this answer




















  • 2





    If you use ~/.profile instead of ~/.bash_profile things will still work even if you change shells.. ~/.bash_profile is for bash specific things.

    – LassePoulsen
    Aug 7 '10 at 8:55






  • 1





    But bash will only run EITHER .bash_profile OR .profile, so if you're going to use both, you need to source .profile from within .bash_profile or something. That isn't a bad idea, actually...

    – Don Faulkner
    Aug 9 '10 at 14:43











  • @Source & @Don : Good points. I used to have Bashisms in my .bash_profile, but now I've switched to something more universal. Maybe using .profile is in order.

    – Stefan Lasiewski
    Aug 9 '10 at 23:26











  • Regarding output-producing commands in .bashrc interfering with remote file transfer methods implemented via standard streams, the solution is to put such commands under code that checks if the shell is interactive and continues only if it is. Users' default .bashrc files in Ubuntu, copied from /etc/skel/.bashrc upon account creation, as well as the systemwide /etc/bash.bashrc, already contain code that checks and returns if the shell is noninteractive (though one must still put one's output-producing commands under them).

    – Eliah Kagan
    Nov 19 '17 at 14:09


















8














Byobu is a great example of something you should never ever put in a .bashrc.



Otherwise, it will recursively run itself in every single one of its 'virtual terminals' ;-)



You can try it though, it's sort of fun.



That why you put it in .profile, so byobu (which really is a just wrapper around screen) is only loaded, once, at login-time. And byobu itself can start new interactive bash sessions.






share|improve this answer

























  • That's a good example. Thanks for the pointer to Byobu as well. Now to go try it out.

    – Don Faulkner
    Sep 7 '10 at 13:12











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1528%2fbashrc-or-bash-profile%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









24














Since a .bashrc is for non-login shells, I avoid any commands which echo to the screen. I've also run into experiences where echo statements in .bashrc will cause sftp and rsync commands to fail (and maybe scp commands as well).



# Print some information as we log in
# -s: OS Name -n: Node name -r: OS Release
uname -snr
uptime


Also, you generally won't run ssh-agent from a non-interactive shell. So I have this in .bash_profile.



if [ -f ~/.ssh/ssh-agent ]; then . ~/.ssh/ssh-agent; fi





share|improve this answer




















  • 2





    If you use ~/.profile instead of ~/.bash_profile things will still work even if you change shells.. ~/.bash_profile is for bash specific things.

    – LassePoulsen
    Aug 7 '10 at 8:55






  • 1





    But bash will only run EITHER .bash_profile OR .profile, so if you're going to use both, you need to source .profile from within .bash_profile or something. That isn't a bad idea, actually...

    – Don Faulkner
    Aug 9 '10 at 14:43











  • @Source & @Don : Good points. I used to have Bashisms in my .bash_profile, but now I've switched to something more universal. Maybe using .profile is in order.

    – Stefan Lasiewski
    Aug 9 '10 at 23:26











  • Regarding output-producing commands in .bashrc interfering with remote file transfer methods implemented via standard streams, the solution is to put such commands under code that checks if the shell is interactive and continues only if it is. Users' default .bashrc files in Ubuntu, copied from /etc/skel/.bashrc upon account creation, as well as the systemwide /etc/bash.bashrc, already contain code that checks and returns if the shell is noninteractive (though one must still put one's output-producing commands under them).

    – Eliah Kagan
    Nov 19 '17 at 14:09















24














Since a .bashrc is for non-login shells, I avoid any commands which echo to the screen. I've also run into experiences where echo statements in .bashrc will cause sftp and rsync commands to fail (and maybe scp commands as well).



# Print some information as we log in
# -s: OS Name -n: Node name -r: OS Release
uname -snr
uptime


Also, you generally won't run ssh-agent from a non-interactive shell. So I have this in .bash_profile.



if [ -f ~/.ssh/ssh-agent ]; then . ~/.ssh/ssh-agent; fi





share|improve this answer




















  • 2





    If you use ~/.profile instead of ~/.bash_profile things will still work even if you change shells.. ~/.bash_profile is for bash specific things.

    – LassePoulsen
    Aug 7 '10 at 8:55






  • 1





    But bash will only run EITHER .bash_profile OR .profile, so if you're going to use both, you need to source .profile from within .bash_profile or something. That isn't a bad idea, actually...

    – Don Faulkner
    Aug 9 '10 at 14:43











  • @Source & @Don : Good points. I used to have Bashisms in my .bash_profile, but now I've switched to something more universal. Maybe using .profile is in order.

    – Stefan Lasiewski
    Aug 9 '10 at 23:26











  • Regarding output-producing commands in .bashrc interfering with remote file transfer methods implemented via standard streams, the solution is to put such commands under code that checks if the shell is interactive and continues only if it is. Users' default .bashrc files in Ubuntu, copied from /etc/skel/.bashrc upon account creation, as well as the systemwide /etc/bash.bashrc, already contain code that checks and returns if the shell is noninteractive (though one must still put one's output-producing commands under them).

    – Eliah Kagan
    Nov 19 '17 at 14:09













24












24








24







Since a .bashrc is for non-login shells, I avoid any commands which echo to the screen. I've also run into experiences where echo statements in .bashrc will cause sftp and rsync commands to fail (and maybe scp commands as well).



# Print some information as we log in
# -s: OS Name -n: Node name -r: OS Release
uname -snr
uptime


Also, you generally won't run ssh-agent from a non-interactive shell. So I have this in .bash_profile.



if [ -f ~/.ssh/ssh-agent ]; then . ~/.ssh/ssh-agent; fi





share|improve this answer















Since a .bashrc is for non-login shells, I avoid any commands which echo to the screen. I've also run into experiences where echo statements in .bashrc will cause sftp and rsync commands to fail (and maybe scp commands as well).



# Print some information as we log in
# -s: OS Name -n: Node name -r: OS Release
uname -snr
uptime


Also, you generally won't run ssh-agent from a non-interactive shell. So I have this in .bash_profile.



if [ -f ~/.ssh/ssh-agent ]; then . ~/.ssh/ssh-agent; fi






share|improve this answer














share|improve this answer



share|improve this answer








edited 4 hours ago









Kevin Bowen

14.9k155971




14.9k155971










answered Aug 7 '10 at 4:20









Stefan LasiewskiStefan Lasiewski

2,48252032




2,48252032







  • 2





    If you use ~/.profile instead of ~/.bash_profile things will still work even if you change shells.. ~/.bash_profile is for bash specific things.

    – LassePoulsen
    Aug 7 '10 at 8:55






  • 1





    But bash will only run EITHER .bash_profile OR .profile, so if you're going to use both, you need to source .profile from within .bash_profile or something. That isn't a bad idea, actually...

    – Don Faulkner
    Aug 9 '10 at 14:43











  • @Source & @Don : Good points. I used to have Bashisms in my .bash_profile, but now I've switched to something more universal. Maybe using .profile is in order.

    – Stefan Lasiewski
    Aug 9 '10 at 23:26











  • Regarding output-producing commands in .bashrc interfering with remote file transfer methods implemented via standard streams, the solution is to put such commands under code that checks if the shell is interactive and continues only if it is. Users' default .bashrc files in Ubuntu, copied from /etc/skel/.bashrc upon account creation, as well as the systemwide /etc/bash.bashrc, already contain code that checks and returns if the shell is noninteractive (though one must still put one's output-producing commands under them).

    – Eliah Kagan
    Nov 19 '17 at 14:09












  • 2





    If you use ~/.profile instead of ~/.bash_profile things will still work even if you change shells.. ~/.bash_profile is for bash specific things.

    – LassePoulsen
    Aug 7 '10 at 8:55






  • 1





    But bash will only run EITHER .bash_profile OR .profile, so if you're going to use both, you need to source .profile from within .bash_profile or something. That isn't a bad idea, actually...

    – Don Faulkner
    Aug 9 '10 at 14:43











  • @Source & @Don : Good points. I used to have Bashisms in my .bash_profile, but now I've switched to something more universal. Maybe using .profile is in order.

    – Stefan Lasiewski
    Aug 9 '10 at 23:26











  • Regarding output-producing commands in .bashrc interfering with remote file transfer methods implemented via standard streams, the solution is to put such commands under code that checks if the shell is interactive and continues only if it is. Users' default .bashrc files in Ubuntu, copied from /etc/skel/.bashrc upon account creation, as well as the systemwide /etc/bash.bashrc, already contain code that checks and returns if the shell is noninteractive (though one must still put one's output-producing commands under them).

    – Eliah Kagan
    Nov 19 '17 at 14:09







2




2





If you use ~/.profile instead of ~/.bash_profile things will still work even if you change shells.. ~/.bash_profile is for bash specific things.

– LassePoulsen
Aug 7 '10 at 8:55





If you use ~/.profile instead of ~/.bash_profile things will still work even if you change shells.. ~/.bash_profile is for bash specific things.

– LassePoulsen
Aug 7 '10 at 8:55




1




1





But bash will only run EITHER .bash_profile OR .profile, so if you're going to use both, you need to source .profile from within .bash_profile or something. That isn't a bad idea, actually...

– Don Faulkner
Aug 9 '10 at 14:43





But bash will only run EITHER .bash_profile OR .profile, so if you're going to use both, you need to source .profile from within .bash_profile or something. That isn't a bad idea, actually...

– Don Faulkner
Aug 9 '10 at 14:43













@Source & @Don : Good points. I used to have Bashisms in my .bash_profile, but now I've switched to something more universal. Maybe using .profile is in order.

– Stefan Lasiewski
Aug 9 '10 at 23:26





@Source & @Don : Good points. I used to have Bashisms in my .bash_profile, but now I've switched to something more universal. Maybe using .profile is in order.

– Stefan Lasiewski
Aug 9 '10 at 23:26













Regarding output-producing commands in .bashrc interfering with remote file transfer methods implemented via standard streams, the solution is to put such commands under code that checks if the shell is interactive and continues only if it is. Users' default .bashrc files in Ubuntu, copied from /etc/skel/.bashrc upon account creation, as well as the systemwide /etc/bash.bashrc, already contain code that checks and returns if the shell is noninteractive (though one must still put one's output-producing commands under them).

– Eliah Kagan
Nov 19 '17 at 14:09





Regarding output-producing commands in .bashrc interfering with remote file transfer methods implemented via standard streams, the solution is to put such commands under code that checks if the shell is interactive and continues only if it is. Users' default .bashrc files in Ubuntu, copied from /etc/skel/.bashrc upon account creation, as well as the systemwide /etc/bash.bashrc, already contain code that checks and returns if the shell is noninteractive (though one must still put one's output-producing commands under them).

– Eliah Kagan
Nov 19 '17 at 14:09













8














Byobu is a great example of something you should never ever put in a .bashrc.



Otherwise, it will recursively run itself in every single one of its 'virtual terminals' ;-)



You can try it though, it's sort of fun.



That why you put it in .profile, so byobu (which really is a just wrapper around screen) is only loaded, once, at login-time. And byobu itself can start new interactive bash sessions.






share|improve this answer

























  • That's a good example. Thanks for the pointer to Byobu as well. Now to go try it out.

    – Don Faulkner
    Sep 7 '10 at 13:12















8














Byobu is a great example of something you should never ever put in a .bashrc.



Otherwise, it will recursively run itself in every single one of its 'virtual terminals' ;-)



You can try it though, it's sort of fun.



That why you put it in .profile, so byobu (which really is a just wrapper around screen) is only loaded, once, at login-time. And byobu itself can start new interactive bash sessions.






share|improve this answer

























  • That's a good example. Thanks for the pointer to Byobu as well. Now to go try it out.

    – Don Faulkner
    Sep 7 '10 at 13:12













8












8








8







Byobu is a great example of something you should never ever put in a .bashrc.



Otherwise, it will recursively run itself in every single one of its 'virtual terminals' ;-)



You can try it though, it's sort of fun.



That why you put it in .profile, so byobu (which really is a just wrapper around screen) is only loaded, once, at login-time. And byobu itself can start new interactive bash sessions.






share|improve this answer















Byobu is a great example of something you should never ever put in a .bashrc.



Otherwise, it will recursively run itself in every single one of its 'virtual terminals' ;-)



You can try it though, it's sort of fun.



That why you put it in .profile, so byobu (which really is a just wrapper around screen) is only loaded, once, at login-time. And byobu itself can start new interactive bash sessions.







share|improve this answer














share|improve this answer



share|improve this answer








edited 4 hours ago









Kevin Bowen

14.9k155971




14.9k155971










answered Sep 6 '10 at 18:31









RalfRalf

1,650118




1,650118












  • That's a good example. Thanks for the pointer to Byobu as well. Now to go try it out.

    – Don Faulkner
    Sep 7 '10 at 13:12

















  • That's a good example. Thanks for the pointer to Byobu as well. Now to go try it out.

    – Don Faulkner
    Sep 7 '10 at 13:12
















That's a good example. Thanks for the pointer to Byobu as well. Now to go try it out.

– Don Faulkner
Sep 7 '10 at 13:12





That's a good example. Thanks for the pointer to Byobu as well. Now to go try it out.

– Don Faulkner
Sep 7 '10 at 13:12

















draft saved

draft discarded
















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1528%2fbashrc-or-bash-profile%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Are there any comparative studies done between Ashtavakra Gita and Buddhim?How is it wrong to believe that a self exists, or that it doesn't?Can you criticise or improve Ven. Bodhi's description of MahayanaWas the doctrine of 'Anatta', accepted as doctrine by modern Buddhism, actually taught by the Buddha?Relationship between Buddhism, Hinduism and Yoga?Comparison of Nirvana, Tao and Brahman/AtmaIs there a distinction between “ego identity” and “craving/hating”?Are there many differences between Taoism and Buddhism?Loss of “faith” in buddhismSimilarity between creation in Abrahamic religions and beginning of life in Earth mentioned Agganna Sutta?Are there studies about the difference between meditating in the morning versus in the evening?Can one follow Hinduism and Buddhism at the same time?Are there any prohibitions on participating in other religion's practices?Psychology of 'flow'

fallocate: fallocate failed: Text file busy in Ubuntu 17.04? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)defragmenting and increasing performance of old lubuntu system with swap partitionIssue with increasing the root partition from the swapthis /usr/bin/dpkg returned error || ubuntu-16.04, 64bitDefault 17.04 swap file locationHow to Resize Ubuntu 17.04 Zesty Swap file size?Ubuntu freezes from online formsMy Laptop is not starting after upgrade ubuntu 16.04 (Kernel 4.8.0-38 to 04.10.0-36)hcp: ERROR: FALLOCATE FAILED!Not sure my swap is being usedWine 3.0 asking for more virtual free swap

Where is the suspend/hibernate button in GNOME Shell? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)No suspend option in UI on Bionic BeaverHow can I set sleep mode in ubuntu18.04 LTS and what is the short cut key to do so?17.10 suspend not availableUbuntu 18.04 LTS missing sleep optionUbuntu 18.04 LTS - missing suspend option when power button is pressedHow to put Thinkpad X1 Extreme to sleep in Ubuntu 18.10?Suspend Button in interactive power button menu18.04 - Keep programs running after logging outway to disable Hibernate from within gconf-editor so button disappears?How can I hibernate from GNOME Shell?How can I hibernate/suspend from the command line and do so at a specific timeNo permission to suspend/hibernate after upgrading to 12.10MATE - Missing Suspend and Hibernate buttons, pressing power button shutdowns system immediatelyUbuntu 14.04: Suspend, Hibernate and Suspend-hybrid in the menu?Change “power-button-action” comand for “hibernate” option in GNOME 3.18Shutdown / Power off button does always go to suspend on 17.10Hibernate after suspend stopped working in 17.10Why doesn't the keyboard screenshot button work on Ubuntu with GNOME shell?