
상황:피쉬 쉘이 있는 여러 원격 서버에 로그인해야 함
요구 사항:기본 쉘은 bash입니다. 서버에 로그인했는데 피쉬가 있으면 피쉬 쉘로 전환하고, 그렇지 않으면 bash를 유지하세요.
.bashrc를 시도했습니다.
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Source global definitions
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
# Update Path
export PATH=/sbin:/usr/sbin:/usr/local/sbin:$PATH:$HOME/.bin
# Open fish shell if present, otherwise stick to bash
if hash fish 2>/dev/null; then
# echo "Fish detected, shifting shell"
fish "$@"; exit
fi
그러나 scp가 작동하지 않는 것 같습니다. 파일을 scp하려고 하면 자세한 출력에 해당 파일이 여기에 멈춘 것으로 표시됩니다.
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_ADDRESS = en_US.UTF-8
debug1: Sending env LC_IDENTIFICATION = en_US.UTF-8
debug1: Sending env LC_MEASUREMENT = en_US.UTF-8
debug1: Sending env LC_MONETARY = en_US.UTF-8
debug1: Sending env LC_NAME = en_US.UTF-8
debug1: Sending env LC_NUMERIC = en_US.UTF-8
debug1: Sending env LC_PAPER = en_US.UTF-8
debug1: Sending env LC_TELEPHONE = en_US.UTF-8
debug1: Sending env LC_TIME = en_US.UTF-8
debug1: Sending command: scp -v -f test_file
echo
처음에는 명령이 작동하지 않는 것으로 생각했지만 명령 없이도 작동하지 않습니다.
답변1
파일을 소싱하는 셸 세션이 대화형이 아닐 때 파일 을 종료하려면 bashrc
파일 상단(또는 편리한 위치)에서 다음을 수행하면 됩니다.
case "$-" in
*i*) ;;
*) return ;;
esac
값은 $-
현재 설정된 쉘 옵션을 나타내는 문자열입니다. i
문자열에 문자가 있으면 쉘은 대화형입니다 .
sshd
terdon이 주석에서 지적했듯이 Bash는 SSH 데몬인 에 의해 시작된 셸 세션을 특별한 경우로 처리하기 때문에 이것이 필요할 수 있습니다 .
세부:bashrc가 현재 쉘이 대화형인지 확인하는 이유는 무엇입니까?
파일 아래에서 fish
셸을 사용할 수 있는지 확인하고 시작할 수 있습니다.
if command -v fish 2>/dev/null; then
exec fish
fi
fish
일부 시스템에서는 "Go Fish" 게임이 나타날 수 있습니다. :-)
사용에 관하여 command -v
:" which "를 사용하지 않는 이유는 무엇입니까? 그러면 무엇을 사용해야 할까요?