{"id":2084,"date":"2011-04-27T17:32:54","date_gmt":"2011-04-27T16:32:54","guid":{"rendered":"http:\/\/mccltd.net\/blog\/?p=2084"},"modified":"2014-04-27T17:36:21","modified_gmt":"2014-04-27T16:36:21","slug":"bashrc-and-bash_profile","status":"publish","type":"post","link":"http:\/\/darenmatthews.com\/blog\/?p=2084","title":{"rendered":"bashrc and bash_profile"},"content":{"rendered":"<p>Both the ~\/.bashrc and ~\/.bash_profile are scripts that might be executed when bash is invoked. The ~\/.bashrc file gets executed when you run bash using an interactive shell that is not a login shell. The ~\/.bash_profile only gets executed during a login shell. What does this all mean? <!--more--><\/p>\n<p>The paragraphs below explains interactive shells, login shells, .bashrc, .bash_profile and other bash scripts that are executed during login.<\/p>\n<p><strong>Login Shells <\/strong>(.bash_profile)<\/p>\n<p>A login shell is a bash shell that is started with &#8211; or &#8211;login. The following are examples that will invoke a login shell.<\/p>\n<p>sudo su &#8211;<br \/>\nbash &#8211;login<br \/>\nssh user@host<\/p>\n<p>When BASH is invoked as a login shell, the following files are executed in the displayed order.<\/p>\n<p>\/etc\/profile<br \/>\n~\/.bash_profile<br \/>\n~\/.bash_login<br \/>\n~\/.profile<\/p>\n<p>Although ~\/.bashrc is not listed here, most default ~\/.bash_profile scripts run ~\/.bashrc.<\/p>\n<p><strong>Purely Interactive Shells<\/strong> (.bashrc)<\/p>\n<p>Interactive shells are those not invoked with -c and whose standard input and output are connected to a terminal. Interactive shells do not need to be login shells. Here are some examples that will evoke an interactive shell that is not a login shell.<\/p>\n<p>sudo su<br \/>\nbash<br \/>\nssh user@host \/path\/to\/command<\/p>\n<p>In this case of an interactive but non-login shell, only ~\/.bashrc is executed. In most cases, the default ~\/.bashrc script executes the system&#8217;s \/etc\/bashrc.<\/p>\n<p>Be warned that you should never echo output to the screen in a ~\/.bashrc file. Otherwise, commands like &#8216;ssh user@host \/path\/to\/command&#8217; will echo output unrelated to the command called.<\/p>\n<p><strong>Non-interactive shells<\/strong><\/p>\n<p>Non-interactive shells do not automatically execute any scripts like ~\/.bashrc or ~\/.bash_profile. Here are some examples of non-interactive shells.<\/p>\n<p>su user -c \/path\/to\/command<br \/>\nbash -c \/path\/to\/command<\/p>\n<p>For more information, see the <a href=\"http:\/\/www.gnu.org\/software\/bash\/manual\/bashref.html\">Bash Reference Manual<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Both the ~\/.bashrc and ~\/.bash_profile are scripts that might be executed when bash is invoked. The ~\/.bashrc file gets executed when you run bash using an interactive shell that is not a login shell. The ~\/.bash_profile only gets executed during a login shell. What does this all mean?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[84],"tags":[],"_links":{"self":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2084"}],"collection":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2084"}],"version-history":[{"count":3,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2084\/revisions"}],"predecessor-version":[{"id":2087,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2084\/revisions\/2087"}],"wp:attachment":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2084"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}