Bash não está lendo (fonte) .bashrc no AIX

0

Por que o bash não está lendo o ~ / .bashrc no AIX em shells não interativos através do ssh? De acordo com a página man bash do link , ele deve fazer isso:

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.

Uma vez executado no AIX 7.1, será necessário também no AIX 5.1.

Versão do AIX : uname -a

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

Versão do Bash : 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 ...

Snippets de arquivos : / etc / environment, / etc / profile, .bash_profile e .bashrc

/ etc / environment :

...
TESTGLOBAL="Defined in /etc/environment"
...

/ etc / profile :

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

.bash_profile :

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

.bashrc :

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

O shell remoto é bash : Mas ele não lê ~ / .bashrc

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

Concha interativa:

$ 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"'

Comandos remotos : Com ou sem o sinalizador -t

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

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

$ ssh -t user@localhost 'set | grep TEST'
BASH_EXECUTION_STRING='set | grep TEST'
TESTGLOBAL='"Defined in /etc/environment"'
    
por Luciano 11.10.2016 / 21:17

1 resposta

3

As camadas não interativas simplesmente não obtêm .bashrc ; é o comportamento definido de bash . Um shell não interativo só fornecerá um arquivo chamado pela variável de ambiente BASH_ENV . (Se executado como sh , ele usa ENV para nomear um arquivo como origem.)

A partir da página man (negrito é minha ênfase)

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.

    
por 11.10.2016 / 22:16

Tags