2
    [ -r "$df" ] && {   
        tail -1 $df | grep "$was_fallback" > /dev/null     
        [ $? -ne 0 ] && { continue; }    

这是更大代码的一部分。我正在阅读一些前辈写的旧代码。然后我找到了这段代码。我知道 [ ] 适用于“如果”条件。但是这个 {} 是做什么用的?

4

1 回答 1

3
I know that [ ] is for 'if' condition

不,这不是if条件。[是测试命令。更多关于它的信息:

test, [ 和 [[ 有什么区别?

what is this {} used for?

这称为命令分组。来自 GNU 手册:

{}

    { list; }

    Placing a list of commands between curly braces causes the list to be
    executed in the current shell context. No subshell is created. 
    The semicolon (or newline) following list is required. 
于 2013-09-30T11:29:49.753 回答