In if [ ... ], I know that [ stands for test. What does ] stands for?
Asked
Active
Viewed 40 times
0
Helin Wang
- 109
]is just an argument of[that prevents further arguments from being used." – muru Jan 05 '21 at 04:17]; a couple of the answers on that other question mention in passing (correctly) that]is just an argument to the[command, but they (incorrectly) say it tells[where the end of the expression is.]can occur within the expression, but it must (also) occur at the end (i.e. as the last argument to[). Try[ foo = baror/usr/bin/[ foo = bar, and you'll get an error message from the[command that "]" is missing. – Gordon Davisson Jan 05 '21 at 04:25if [ ] = foo ]; then echo yes; else echo no; fivsif [ ] = ] ]; then echo yes; else echo no; fi. In both cases,]occurs as the first argument to[, but it does not prevent the other arguments from being parsed as part of the expression. – Gordon Davisson Jan 05 '21 at 04:28[stands fortest” — it doesn’t,[andtestare slightly different (in particular,[requires],testdoesn’t, and will fail with an extra]). On my system they aren’t even the same binary. – Stephen Kitt Jan 05 '21 at 10:12