Running into a weird error while writing a shell script.
The following works perfectly fine...
#!/bin/sh
if ssh root@example.com "[ -d /web ]"; then
echo "That directory exists!";
fi
And runs without error. Once I try using variables however...
#!/bin/sh
USER="root"
LOC="example.com"
PATH="/web"
if ssh $USER@$LOC "[ -d $PATH ]"; then
echo "That directory exists!";
fi
it just returns...
6: test.sh: ssh: not found
Even just setting the variables at the top and leaving the bottom hard coded makes it throw this error.
$PATH
is being used by the local shell to find binaries, in this case ssh
. As soon as you set it to /web
, the shell will try to locate /web/ssh
which does not exist.
Use a different variable name:
remote_path="/web"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.