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".

help [
click below button to copy the code. By - Linux tutorial - team

However while they do exactly the same, test turns out to have a more detailed help page. Check

help test
click below button to copy the code. By - Linux tutorial - team

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:

command arguments separated with space
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 4:

[ is a test command. So it requires space.


Related Searches to - linux - linux tutorial - Why should there be a space after '[' and before ']' in Bash