Linux 在shell脚本中使用变量时未找到ssh
在编写shell脚本时遇到奇怪的错误 下面的工作非常好Linux 在shell脚本中使用变量时未找到ssh,linux,shell,Linux,Shell,在编写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
#!/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用于查找二进制文件,在本例中是ssh
。一旦将其设置为/web
,shell将尝试查找不存在的/web/ssh
使用不同的变量名:
remote_path="/web"
正在被本地shell用于查找二进制文件,在本例中为ssh
。一旦将其设置为/web
,shell将尝试查找不存在的/web/ssh
使用不同的变量名:
remote_path="/web"
如果他需要,您可以解释如何将
web
添加到路径变量:)中。这没有意义。如果他需要,您可以解释如何将web
添加到路径变量:)中。这没有意义。