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: Greg Wooledge
Subject: Re: bash 'if [[ <cond> ]]; then ...fi' should 'then' be redundant?
Date: Thu, 7 May 2020 08:39:22 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Thu, May 07, 2020 at 12:05:41PM +0000, Vang Le-Quy wrote:
> 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 actual syntax is:

if COMMAND LIST ONE
then COMMAND LIST TWO
else COMMAND LIST THREE
fi

You can have more than one command in each list.  A command whose first
word is "then" or "else" or "fi" or "elif" signifies the end of a
list.

Silly example:

if true; false; true; then echo yes; fi

Slightly better example:

if tmp=${input##*\[}; tmp=${tmp%%\]*; [[ $tmp = ABC ]]; then echo match; fi



reply via email to

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