linux - [Solved-4 Solutions] Why should there be a space after '[' and before ']' in Bash - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
Why should there be a space after '[' and before ']' in Bash ?
Linux - Solution 1:
Once you grasp that [ is a command, a whole lot becomes clearer.
[ is another way to spell "test".
However while they do exactly the same, test turns out to have a more detailed help page. Check
Linux - Solution 2:
'[' was historically not a shell-built-in but a separate executable that received the expresson as arguments and returned a result. If you didn't surround the '[' with space, the shell would be searching $PATH for a different filename.
Linux - Solution 3:
[ is a command and $CHOICE should be an argument, but by doing [$CHOICE (without any space between [ and $CHOICE) you are trying to run a command named [$CHOICE. The syntax for command is:
Linux - Solution 4:
[ is a test command. So it requires space.