Should we use [[ or should we use [ when the later will do? (Was: Execution of subsequent commands ...)

Stan Marsh <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <[email protected]>
From:	Chet Ramey
Subject: Re: Execution of subsequent commands after a command crashes.
Date:	Tue, 3 Feb 2026 09:37:13 -0500

>On 2/2/26 10:29 PM, Robert Elz wrote:

>> ps: it is really dumb to use bash extensions when standard portable
>> POSIX shell code works equally well, "[[ $? -ne 0 ]]" is not in the
>> slightest different from "[ $? -ne 0 ]" and the latter will work in
>> any shell - so use the latter, not the former.

I think it is dumb to publicly call another poster "dumb".

Chet wrote:

>On the other hand, there's no problem with using bash features when
>you're writing a bash script and don't have to be concerned about
>portability.

I've seen posts that say that you should always use [[ in new code,
simply because it is better behaved and can do everything that [ can
do (and better).  I'm not sure I agree with this, but I see their
point.

Personally, I still use [ when it is sufficient, and only use [[ when
it seems appropriate (*), but I realize that this may not be
absolutely best practice.  I certainly don't do this out of any sort
of obsession with "POSIX".

(*) Usually, specifically because I want to use =~

=================================================================================
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.

When responding to my posts, please try to refrain from giving bureaucratic answers.
If you have nothing useful to say, then just click Next and go on.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.