-1

This is the code of the my shell script:

#! /bin/bash

if ["$SHELL" = "/bin/bash"];then
        echo "this is bash"
elif ["$SHELL" = "aa"];then
        echo "this is aa"
else
        echo "this is not /bin/bash, but $SHELL"
fi

why I execute the test_bash_03 script file gets the else result? shouldn't it be:this is bash

aircraftdeMacBook-Pro:bash_demo ldl$ ./test_bash_03
./test_bash_03: line 3: [/bin/bash: No such file or directory
./test_bash_03: line 5: [/bin/bash: No such file or directory
this is not /bin/bash, but /bin/bash

And I echo the $SHELL I also get the /bin/bash

aircraftdeMacBook-Pro:bash_demo ldl$ echo $SHELL
/bin/bash
aircraft
  • 25,146
  • 28
  • 91
  • 166

1 Answers1

1

You are missing a space after [ and before ].

The bash tries to execute a command named [/bin/bash instead of [ (which is test), then doesn't find that and has an exit code of 1 (false). So you end up in the else case.

Alfe
  • 56,346
  • 20
  • 107
  • 159