0

I am trying to find out it a remote directory exists or not. However I just cannot manage to do it.

So far I tried the following

if [ ssh myUser@myHost '[ -d /home/targetDirectory ]' ] ; then
    echo "Directory does exist"
fi

But I keep getting the error ssh binary operator expected. I dont see what am I doing wrong here.

malajedala
  • 867
  • 2
  • 8
  • 22

1 Answers1

0

You got it, nearly.
Remove the outer brackets

if ssh myUser@myHost '[ -d /home/targetDirectory ]' ; then
    echo "Directory does exist"
fi
jeb
  • 78,592
  • 17
  • 171
  • 225
  • but why do I need to remove the outer brackets? I mean, how does bash interprets it with and without? – malajedala Jan 16 '20 at 08:44
  • In the comment from @chepner is the key point, also look at [How to check the exit status using an if statement](https://stackoverflow.com/a/26675771/463115) – jeb Jan 16 '20 at 09:21
  • Ok, maybe I have to put some more time in understanding this, so far it is still confusing – malajedala Jan 16 '20 at 15:07