이걸 고려하세요:
$ ssh localhost bash -c 'export foo=bar'
terdon@localhost's password:
declare -x DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
declare -x HOME="/home/terdon"
declare -x LOGNAME="terdon"
declare -x MAIL="/var/spool/mail/terdon"
declare -x OLDPWD
declare -x PATH="/usr/bin:/bin:/usr/sbin:/sbin"
declare -x PWD="/home/terdon"
declare -x SHELL="/bin/bash"
declare -x SHLVL="2"
declare -x SSH_CLIENT="::1 55858 22"
declare -x SSH_CONNECTION="::1 55858 ::1 22"
declare -x USER="terdon"
declare -x XDG_RUNTIME_DIR="/run/user/1000"
declare -x XDG_SESSION_ID="c5"
declare -x _="/usr/bin/bash"
bash -c세션 내에서 변수 를 ssh를 통해 내보내는 이유는 declare -x명령 목록 (내가 알 수있는 한 현재 내 보낸 변수 목록)을 초래 하는 이유는 무엇 입니까?
없이 동일한 것을 실행하면 bash -c그렇게하지 않습니다.
$ ssh localhost 'export foo=bar'
terdon@localhost's password:
$
다음과 같은 경우에도 발생하지 않습니다 export.
$ ssh localhost bash -c 'foo=bar'
terdon@localhost's password:
$
우분투 컴퓨터에서 다른 컴퓨터로 bash 4.3.11을 실행하여 위의 bash 버전 4.4.5와 같이 아치 컴퓨터에서 sshing하여 테스트했습니다.
무슨 일이야? bash -c호출 내에서 변수를 내 보내면 왜이 출력이 생성됩니까?
export무엇인지 이해하려고 노력하고 있습니다. 내보내기 할 때만 발생한다는 것을 명확히하기 위해 편집 할 것입니다.
export혼자 실행 의 결과를 의미 합니까? 나는 이해하지 못했다.
foo=bar목록에 표시되지 않습니다.
export. Zsh도 마찬가지입니다.