Octoxan
Octoxan

Reputation: 2309

ssh not found when using variable in shell script

Running into a weird error while writing a shell script.

The following works perfectly fine...

#!/bin/sh
if ssh [email protected] "[ -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.

Upvotes: 0

Views: 316

Answers (1)

hek2mgl
hek2mgl

Reputation: 158220

$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"

Upvotes: 3

Related Questions