!['-sh: 구문 오류: 임베디드 Linux 장치에서 프로세스 대체를 위해 'bash'를 사용하려고 할 때 예기치 않은 '(''](https://linux55.com/image/198142/'-sh%3A%20%EA%B5%AC%EB%AC%B8%20%EC%98%A4%EB%A5%98%3A%20%EC%9E%84%EB%B2%A0%EB%94%94%EB%93%9C%20Linux%20%EC%9E%A5%EC%B9%98%EC%97%90%EC%84%9C%20%ED%94%84%EB%A1%9C%EC%84%B8%EC%8A%A4%20%EB%8C%80%EC%B2%B4%EB%A5%BC%20%EC%9C%84%ED%95%B4%20'bash'%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EB%A0%A4%EA%B3%A0%20%ED%95%A0%20%EB%95%8C%20%EC%98%88%EA%B8%B0%EC%B9%98%20%EC%95%8A%EC%9D%80%20'(''.png)
이는 다음을 사용합니다."프로세스 대체"( <()
) 그리고"흐리독"( cat << EOF...EOF
)는 새로운 bash 프로세스를 열고 여기에 --rcfile
include를 실행합니다 alias foo="echo hey you
.
bash --rcfile <(
cat << EOF
alias foo="echo hey you"
EOF
)
여기에서 볼 수 있듯이 우분투에서는 잘 실행됩니다.
$ bash --rcfile <(
> cat << EOF
> alias foo="echo hey you"
> EOF
> )
$ foo
hey you
$ alias
alias foo='echo hey you'
그러나 일부 임베디드 Linux 장치에서 이 프로그램을 실행하려고 하면 다음과 같은 오류가 발생합니다. 왜? 거기에서도 실행되도록 하려면 어떻게 해야 합니까?
-sh: syntax error: unexpected "("
전체 출력:
$ bash --rcfile <( -sh: syntax error: unexpected "(" $ cat << EOF > alias foo="echo hey you" > EOF alias foo="echo hey you" $ ) -sh: syntax error: unexpected ")"
도움이 된다면 Linux 장치가 내장된 Ubuntu에서의 출력은 다음과 같습니다 which bash
.bash --version
# 1. Ubuntu
$ which bash
/bin/bash
$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
# 2. Embedded Linux device
$ which bash
/bin/bash
$ bash --version
GNU bash, version 5.0.16(1)-release (aarch64-buildroot-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
반복하지 않음:
이것은 관련이 있지만아니요중복된 것 같습니다.프로세스 대체를 사용할 때 Dash가 "구문 오류: "(" 예기치 않은" 오류를 보고합니다..
관련된:
자신에 대한 메모
나의 궁극적인 목표는 SSH 로그인 시 다음과 같이 일부 사용자 정의 별칭을 자동으로 생성하는 것입니다.
ssh -t username@ip_address '/bin/bash --rcfile <(
cat << EOF
alias foo="echo hey you"
EOF
)'
업데이트 완료! 이것이 내가 생각해낸 것입니다:
# Store your password into a file
echo "my_password" > ~/pw
# Manually add something like this to your ~/.bash_aliases (recommended) or ~/.bashrc file on the PC
# you are ssh-ing FROM:
alias gs_ssh="sshpass -f ~/pw scp /etc/skel/.bashrc [email protected]:/tmp \
&& sshpass -f ~/pw ssh -t -o 'ServerAliveInterval 60' [email protected] 'bash --rcfile /tmp/.bashrc'"
여기에서 내 저장소를 확인하세요.https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/tree/master/home/.ssh#Optional-but-recommended-alias.
답변1
임베디드 Linux 장치는 /dev/fd/
항목을 지원합니까? 이렇게 하려면 다음과 같이 파일 설명자 #3을 통해 초기화 명령을 전달해 보세요.
bash --rcfile /dev/fd/3 3<<EOF
alias foo="echo hey you"
exec 3<&-
EOF
편집: Stéphane Chazelas는 이것을 exec 3<&-
"스크립트"의 마지막 명령으로 추가할 것을 제안했습니다. 이렇게 하면 파일 설명자가 닫혀서 전체 쉘 세션 동안 멈추지 않습니다.
답변2
명령 구문이 지원되는지 여부는 현재 실행 중인 셸에 따라 다릅니다.
현재 쉘은 명령을 sh
실행하려고 할 때 발생하는 것이며, 쉘이 로그인 쉘로 실행되는 쉘로 bash --rcfile <(...)
자신을 식별한다는 것은 오류 메시지에서 분명합니다 . sh
쉘은 일반적으로 프로세스 대체를 이해하지 못합니다.
이 문제를 해결하는 한 가지 방법은 먼저 exec bash
현재 셸을 프로세스 대체를 이해하는 셸로 바꾸거나 다음을 수행하는 것입니다.Gordon Davidson이 제안한대로대체 파일 설명자를 통해 임시 초기화 파일을 제공합니다.
exec bash
bash --rcfile <( cat <<'BASHRC'
alias foo='echo bumblebee'
BASHRC
)
bash --rcfile /dev/fd/3 3<<'BASHRC'
alias foo='echo bumblebee'
exec 3<&-
BASHRC
두 경우 모두 새 쉘이 문서를 읽기 전에 문서를 확장하기 위해 현재 쉘이 필요하지 않은 한 여기서 문서를 참조하는 것이 가장 좋습니다 bash
. exec bash
현재 쉘을 완전히 교체하려는 경우에도 사용할 수 있습니다.