Ten*_*uan 1 linux shell bash bourne-shell
#!/bin/sh
echo -n "Enter the raspberry ip address you want to connect:"
read Rasp_id
sshpass -p "the@Donut" ssh -t -X -oStrictHostKeyChecking=no pi@$Rasp_id << E2
echo -e "Enter the case you want to echo\n 1.1 a \n 2.1 b"
read option
case "\$option" in
1)
echo "a"
;;
2)
echo "b"
;;
esac
E2
Run Code Online (Sandbox Code Playgroud)
我正在编写一个启动 ssh 会话然后在远程机器上执行一些修改的脚本,它会给出如下语法错误:
bash: line 3: syntax error near unexpected token `)'
bash: line 3: ` 1)'
Run Code Online (Sandbox Code Playgroud)
问题是您正在混合使用 stdin 的内容,提供要在远程机器上执行的程序和该程序的输入。
正如所写的,发生了以下情况。
echo -e "Enter the case you want to echo\n 1.1 a \n 2.1 b"
从 stdin读取并执行回显。read option
从 stdin读取并进行读取。read
读取case "\$option" in
从标准输入和设置选项来此。1)
从 stdin获取并给你一个语法错误。