Why bash isn't reading the ~/.bashrc in AIX in non-interactive shells through ssh ? According to bash man page in https://www.gnu.org/software/bash/manual/bash.html it should do this:

Invoked by remote shell daemon

Bash attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If Bash determines it is being run in this fashion, it reads and executes commands from ~/.bashrc, if that file exists and is readable. It will not do this if invoked as sh. The --norc option may be used to inhibit this behavior, and the --rcfile option may be used to force another file to be read, but neither rshd nor sshd generally invoke the shell with those options or allow them to be specified.

Once running in AIX 7.1 it will be necessary also in AIX 5.1.

AIX Version: uname -a

AIX p740 1 7 ???????????? powerpc AIX

Bash version: bash --version

GNU bash, version 4.3.42(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html ...

Files snippets: /etc/environment, /etc/profile, .bash_profile, and .bashrc


TESTGLOBAL="Defined in /etc/environment"


# First line
echo "Loading /etc/profile..."


# First line
echo "Loading .bash_profile..."
[ -e ~/.bashrc ] && . ~/.bashrc


# First line
echo "Loading .bashrc..."
export TESTLOCAL="Defined in ~/.bashrc"

Remote shell is bash: But it doesn't read ~/.bashrc

$ ssh -t user@localhost 'echo $SHELL, $0'
/bin/bash, bash

Interactive shell:

$ ssh user@localhost
*                                                                             *
*                                                                             *
*  Welcome to AIX Version 7.1!                                                *
*                                                                             *
*                                                                             *
*  Please see the README file in /usr/lpp/bos for information pertinent to    *
*  this release of the AIX Operating System.                                  *
*                                                                             *
*                                                                             *
Loading /etc/profile...
Loading .bash_profile...
Loading .bashrc...
$ set | grep TEST
TESTLOCAL='Defined in .bashrc'
TESTGLOBAL='"Defined in /etc/environment"'

Remote commands: With or without -t flag

$ ssh -t user@localhost 'echo $TESTLOCAL'

$ ssh -t user@localhost 'echo $TESTGLOBAL'
"Defined in /etc/environment"

$ ssh -t user@localhost 'set | grep TEST'
TESTGLOBAL='"Defined in /etc/environment"'
  • Pretty much normal default behaviour when passing commands to ssh. Oct 11, 2016 at 19:41
  • /etc/environment is not a standard shell configuration file, but it is probably processed by some ancestor of sshd, which means the value of TESTGLOBAL is inherited by whatever process ssh ultimately runs. Its value is not set by any configuration file when user logs in.
    – chepner
    Oct 11, 2016 at 19:55
  • No. This isn't the expected according to this, @RuiFRibeiro: ibm.com/developerworks/aix/library/au-speakingunix10
    – Luciano
    Oct 11, 2016 at 20:01
  • /etc/environment isn't the question @chepner. This was included only to show some custom variable being set.
    – Luciano
    Oct 11, 2016 at 20:03
  • Luciano, that DW page is a little misleading in the 3rd paragraph of "Planning for the big Bash"; read further down where it talks about non-interactive shells
    – Jeff Schaller
    Oct 11, 2016 at 20:05

1 Answer 1


Non-interactive shells simply do not source .bashrc; it's the defined behavior of bash. An non-interactive shell will only source a file named by the BASH_ENV environment variable. (If run as sh, then it uses ENV instead to name a file to source.)

From the man page (bold is my emphasis)

When bash is invoked as an interactive login shell, or as a non-inter- active shell with the --login option, it first reads and executes com- mands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

When bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute. Bash behaves as if the following com- mand were executed: if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi but the value of the PATH variable is not used to search for the file- name.

  • Can you give us more references that explains and ensures that bash in non-interactive shell doesn't read .bashrc ? That isn't what happen in Linux bash, and is spread over internet, like this answer: unix.stackexchange.com/a/170499/114939
    – Luciano
    Oct 11, 2016 at 20:26
  • @Luciano see the "non-interactive shell" part of that answer -- no ~/.bashrc
    – Jeff Schaller
    Oct 11, 2016 at 20:28
  • Right, maybe a misunderstood in the header "Non-interactive" of my question (I fixed it), it seems to be interactive (non-login), ssh -t user@localhost command is "interactive non-login", it has a input attached by a network stream, so .bashrc should be read, but it isn't. According to "Invoked by remote shell daemon" in gnu.org/software/bash/manual/bash.html
    – Luciano
    Oct 11, 2016 at 20:37
  • No interactive shell is being run by ssh. Run echo $- in your current shell, and observe the i in the output (which means the current shell is an interactive shell). Now run ssh localhost 'echo $-', and observe the absence of i in the output indicating it is not an interactive shell.
    – chepner
    Oct 11, 2016 at 20:45
  • Maybe there are concept conflicts in the bash man pages, I prefer to not discuss the concept of interactive vs non-interactive. I need only the bash to read .bashrc when a command is remotely run by ssh or rsh. Like should do and is described in the bash man pages in the "Invoked by remote shell daemon" in gnu.org/software/bash/manual/bash.html (in Linux it works, but in AIX no)
    – Luciano
    Oct 11, 2016 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.