
저는 RHEL6(커널 2.6.32-573.el6.x86_64)을 실행 중입니다. ssh
에 ing할 때 소스가 되는 별칭이 있습니다 myserver
. 이들 중 하나는
alias scl-devtoolset-3='source /usr/local/bin/scls/devtoolset-3'
아마도 비로그인 쉘에서 별명이 붙었을 것입니다(아래 참조). 그러나 ssh
ing은 로그인 쉘을 제공하며 이는 다음 행으로 확인됩니다.
shopt -q login_shell && echo 'This is a login shell' || echo 'This is a non-login shell'
내 ~/.bashrc
에서
This is a login shell
예상대로. 따라서 별칭이 왜/어디에 설정되어 있는지 전혀 알 수 없습니다.
모순처럼 보이는 이 상황을 어떻게 합리화할 수 있을까요?
내 시스템에 있는 파일:
/etc/profile
/etc/bashrc
/etc/profile.d/*
~/.bashrc
내 시스템에 없는 파일:
/etc/bash.bashrc
~/.profile
TL;DR
별칭은 다음 줄에 의해 설정된 것으로 보입니다(비로그인 쉘에서만) /etc/bashrc
.
...
if ! shopt -q login_shell ; then # We're not a login shell
...
# Only display echos from profile.d scripts if we are no login shell
# and interactive - otherwise just process them to set envvars
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. "$i"
else
. "$i" >/dev/null 2>&1
fi
fi
done
...
fi
어떤 소스 파일이 /etc/profile.d/scl-aliases.sh
포함되어 있는지
#!/bin/bash
sources_dir=/usr/local/bin/scls
for scl in `ls $sources_dir`; do
alias scl-$scl="source $sources_dir/$scl"
done
그리고 그걸 감안할 때
$ ls /usr/local/bin/scls
devtoolset-3 devtoolset-4 devtoolset-6 python27 python33
bash -x
이는 ing 후 명령 프롬프트에서 실행하여 (부분적으로?) 확인되었습니다 ssh
.
답변1
이는 실제로 정상적인 동작입니다. 이는 로그인 스크립트와 비로그인 스크립트에 의해 소스가 다른 파일로 귀결됩니다. 이것은다른 곳에서도 광범위하게 다루어짐그러나 간단히 말해서 (대화형) 비로그인 bash 쉘은 bashrc 파일 계열( /etc/bash.bashrc
, ~/.bashrc
)을 소스로 하고 (대화형) 로그인 쉘은 다양한 프로필 파일( /etc/profile
, ~/.profile
)을 소스로 사용합니다.
따라서 귀하의 /etc/bashrc
(내 생각에 이는 macOS 및 아마도 다른 시스템과 동일하다고 생각합니다 /etc/bash.bashrc
) 대화형 비로그인 셸에서만 읽을 수 있으며원격 쉘 데몬. 해당 파일을 읽을 때 이를 읽는 셸이 비로그인 셸(즉, 원격 셸 데몬이 아님)인 경우 /etc/profile.d
.
그러나 로그인 쉘은 이 파일을 읽지 않으므로 여기서는 관련이 없습니다. 대신, 그들은 읽고 /etc/profile
해당 파일을 확인하면 다음과 같은 내용을 찾을 수 있습니다( /etc/profile
내 아치의 파일에서).
# Load profiles from /etc/profile.d
if test -d /etc/profile.d/; then
for profile in /etc/profile.d/*.sh; do
test -r "$profile" && . "$profile"
done
unset profile
fi
이것이 바로 로그인 셸에서 이러한 내용을 볼 수 있는 이유입니다. 로그인 쉘은 작동하지 않고 대신 자체 설정 파일을 갖고 있으며 로그인 쉘을 제외하지 않고 bashrc
파일을 가져오기 때문입니다./etc/profile.d
답변2
댓글에 들여쓰기된 코드가 있을 수 없기 때문에 답변으로 게시하고 있습니다. 감사합니다terdon의 답변.
terdon이 명시한 대로 my에는 /etc/profile
다음 줄이 있습니다.
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null 2>&1
fi
fi
done
이들은 가 아닌 별칭을 담당합니다 /etc/bashrc
. 이는 솔루션을 통해 쉽게 확인할 수 있습니다.SSH에서 실행되는 스크립트/명령의 추적 순서