0

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.

1 Answer 1

3

$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"
Sign up to request clarification or add additional context in comments.

2 Comments

You could explain how to add web to the PATH variable :) if he need it.
That does not make sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.