.profile non è caricato su non-login / bin / sh

2

Il problema è nel titolo, ma lasciatemi aggiungere alcuni dettagli qui.

Sto correndo su OS X 10.10.5 (14F27) . Utilizzando Terminal.app predefinito.

Contenuto dei file di configurazione

Contenuto di /etc/profile

echo " # reading /etc/profile"
# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
    eval '/usr/libexec/path_helper -s'
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi

Contenuto di /etc/bashrc

echo " # reading /etc/bashrc"
# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
   return
fi

PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
# Tell the terminal about the working directory at each prompt.
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then
    update_terminal_cwd() {
        # Identify the directory using a "file:" scheme URL,
        # including the host name to disambiguate local vs.
        # remote connections. Percent-escape spaces.
    local SEARCH=' '
    local REPLACE='%20'
    local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
    printf '\e]7;%s\a' "$PWD_URL"
    }
    PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND"
fi

Contenuto di ~/.profile

echo " # reading ~/.profile"
...

Contenuto di ~/.bashrc

echo " # reading ~/.bashr"
...
source /etc/profile
...

Contenuto di ~/.bash_profile

echo " # reading ~/.bash_profile"
source ~/.profile
source ~/.bashrc

Output di chiamate sh e bash

Quindi ecco l'output di invocare sh .

$ sh
sh-3.2$ 

sh --login
 # reading /etc/profile
 # reading /etc/bashrc
 # reading ~/.profile
d12frosted:~ d12frosted$ 

$ bash
 # reading ~/.bashr
 # reading /etc/profile
 # reading /etc/bashrc
d12frosted:~ d12frosted$ 

$ bash --login 
 # reading /etc/profile
 # reading /etc/bashrc
 # reading ~/.bash_profile
 # reading ~/.profile
 # reading ~/.bashr
 # reading /etc/profile
 # reading /etc/bashrc
d12frosted:~ d12frosted$ 

Come puoi vedere, quando chiami sh - non carica nessuna configurazione. C'è qualcosa di rotto nel mio ambiente o è previsto?

    
posta d12frosted 01.10.2015 - 15:37
fonte

1 risposta

6

Ci si aspetta che sh carichi solo ~ / .profile quando si tratta di una shell di login.

Da manuale di riferimento Bash

If Bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well.

When invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order. The --noprofile option may be used to inhibit this behavior. When invoked as an interactive shell with the name sh, Bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option has no effect. A non-interactive shell invoked with the name sh does not attempt to read any other startup files.

Vuoi che bash esegua come sh l'uso di ~ / .profile quando non è una shell di login (ad esempio, mantieni l'ambiente corrente)

env ENV=$HOME/.profile /bin/sh
    
risposta data 01.10.2015 - 15:55
fonte

Leggi altre domande sui tag