在编写shell脚本时遇到一个奇怪的错误。
以下工作得很好...
#!/bin/sh
if ssh root@example.com "[ -d /web ]"; then
echo "That directory exists!";
fi
并且运行没有错误。但是,一旦我尝试使用变量...
#!/bin/sh
USER="root"
LOC="example.com"
PATH="/web"
if ssh $USER@$LOC "[ -d $PATH ]"; then
echo "That directory exists!";
fi
它只是返回...
6: test.sh: ssh: not found
即使只是在顶部设置变量并让底部进行硬编码,也会引发此错误。
本地shell 正在使用$PATH
来查找二进制文件,在本例中为ssh
.一旦你把它设置为/web
,shell 将尝试找到不存在/web/ssh
。
使用不同的变量名称:
remote_path="/web"