help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash 'if [[ <cond> ]]; then ...fi' should 'then' be redundant?


From: Chet Ramey
Subject: Re: bash 'if [[ <cond> ]]; then ...fi' should 'then' be redundant?
Date: Thu, 7 May 2020 08:44:24 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

On 5/7/20 8:05 AM, Vang Le-Quy wrote:
> Ever since I wrote my first bash `if`, I was told to immediately use `then`. 
> This structure become so familiar:
> 
> ```
> if  [[ <condition> ]]; then
>                 statements
> else
>                 statements
> fi
> 
> ```
> 
> There might be a historical reason for `then` to be in there. But would it 
> just be straight forward without `then`? What is ambiguous about it?

The command after the `if' is any command list, not just a conditional
command. You use `then' to separate it from the true case command list.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]