0

I have a simple bash script given below

readlink $MY_LINK

if [$?  != "$TEST_DIR/$PCD_NAME/bin/test2"]; then
    rm $MY_LINK
    ln -s $TEST_DIR/$PCD_NAME/bin/test2 $MY_LINK
fi

When I run the script, I am getting the error.

./test.sh: line 6: [1: not found

What am I doing wrong?

liv2hak
  • 14,472
  • 53
  • 157
  • 270
  • 1
    Whenever you have a shell script error, a good first step is to cut and paste your code into [shellcheck.net](http://www.shellcheck.net/) and correct the errors (important) and warnings (might be important) that it identifies. If you have trouble understanding its messages, then come here and ask. – John1024 Jul 05 '18 at 21:06
  • Keep in mind that `[` is the name of a command (there's a built-in version as a performance optimization, but there's also `/usr/bin/[` as the original/external version). Like any other command, whitespace matters -- you can't run `lsfoo.txt` instead of `ls foo.txt`. – Charles Duffy Jul 05 '18 at 21:10
  • 1
    ...that said, another issue is that `$?` is *exit status* -- an unsigned integer. A program will never have an exit status that contains the string `test2` (or any other value that isn't a number between 0 and 255). – Charles Duffy Jul 05 '18 at 21:11

0 Answers0