1

I am trying to create a script to compare an inputted string to an empty value. The logic works, but I keep receiving the following error:

./demo.sh: line 13: [[/var: No such file or directory

Here is the code block that I am struggling with:

read -p "Hello, please enter the target installation path: [/opt] " depl

echo "You have chosen to deploy in $depl"

echo "Now deploying in $depl..."

if [[$depl == ""]];
        then
        echo "Invalid input, cannot write to root!"
        else
        sleep 2
        mkdir $depl/new
        echo "Deployment complete!"
fi

I have tried adding my target inputs to $PATH which does not help. Everything else is working fine, but I am just not understanding why this error is being thrown. Any insight would be much appreciated!

Reboot
  • 11
  • 2
  • 3
    You need spaces between `[[` and `$depl`, and also between `""` and `]]`. And you should put double-quotes around `$depl/new`. [shellcheck.net](https://www.shellcheck.net) is good at spotting common mistakes like these. Also, [stack overflow](https://stackoverflow.com) would be a much better place for scripting questions like this. – Gordon Davisson May 27 '20 at 16:40
  • @GordonDavisson - thanks for your reply. I have already tried that combination, but I am still getting the same results. The script itself is actually working, but I just can't figure out where this error is coming from. – Reboot May 27 '20 at 16:47
  • Update, I used the website you had suggested and apparently I had missing spaces before and after the brackets. Thanks! – Reboot May 27 '20 at 16:48
  • @Reboot please close this – Jacob Evans May 27 '20 at 18:56
  • @GordonDavisson Thank you, spellcheck.net helped me a lot – temo Dec 26 '20 at 14:53

0 Answers0