考虑以下文本文件
test-1 :
echo "hello"
echo "cruel"
echo "world"
发出以下命令:
bash < test-1
所有3行都被执行。
现在,让我们介绍一下文件中的一些变化
test-2 :
echo "hello"
ssh username@192.168.0.100 "echo HELLO > /tmp/file"; echo "cruel"
echo "world"
使用
运行bash < test-2
仅执行以下命令:
echo "hello"
ssh username@192.168.0.100 "echo HELLO > /tmp/file"
echo "cruel"
最后一行或实际上包含 ssh 的行之后的任何行都将被忽略!
为什么?
以及如何解决?
问题似乎与 bash 有关。
例如在Ubuntu上的问题sh < test-2
,其中 sh 不是 bash ,并且所有行都将正确执行,但是在CentOS上,其中 sh < / strong>映射到 bash ,包含 ssh 的一行之后的所有行将被删除。