The square brackets are a synonym for the test
command. An if
statement checks the exit status of a command in order to decide which branch to take. grep -q "$text"
is a command, but "$name" = 'Bob'
is not--it's just an expression. test
is a command, which takes an expression and evaluates it:
if test "$name" = 'Bob'; then ...
Since square brackets are a synonym for the test
command, you can then rewrite it as your original statement:
if [ "$name" = 'Bob' ]; then ...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…