Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
17 events
when toggle format what by license comment
Nov 3 at 16:04 comment added Travis Runyard I disagree with this answer for the sole reason that in Bash, [ is a shell builtin and [[ is a shell keyword. You can find this out by typing type -t [ and type -t [[. I can't think of any hard reasons when [ could be preferred over [[ but I know there is one that doesn't concern about portability.
Nov 25, 2021 at 13:33 review Suggested edits
Dec 8, 2021 at 21:20
Jul 25, 2017 at 18:07 comment added Yordan Georgiev set -u # the only one working with set -u if [[ ${variable+x} && -n $var ]] ; then echo " defined and not null fi
May 23, 2017 at 11:33 history edited CommunityBot
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Dec 1, 2016 at 3:11 comment added Bruno Bronosky You can do that, but a puppy dies every time you put then on its own line.
Nov 30, 2016 at 23:52 comment added Dennis Williamson @BrunoBronosky: I reverted the edit. There's no requirement for ; at the end. The then can be on the next line without a semicolon at all.
Nov 30, 2016 at 23:51 history rollback Dennis Williamson
Rollback to Revision 3
Nov 30, 2016 at 23:24 comment added Bruno Bronosky I edited the answer to make it clear that using [[ instead of [ eliminates the need for " inside but doesn't eliminate the need for ; at the end.
Nov 30, 2016 at 23:23 history edited Bruno Bronosky CC BY-SA 3.0
Make it clear that using [[ instead of [ eliminates the need for " inside but doesn't eliminate the need for ; at the end.
Sep 1, 2015 at 21:12 comment added user248704 You should add if ! [[ $variable ]] and if ! [[ "$variable" ]] to be complete.
Nov 24, 2014 at 13:59 comment added Dennis Williamson @AlastairIrvine: I mention portability in the first sentence of my answer, the question title and body contain the word "Bash" and the question is tagged bash, and the double bracket structure provides clear advantages in many ways. And I don't recommend mixing bracket styles for reasons of consistency and maintainability. If you need maximum, lowest common denominator portability, use sh instead of Bash. If you need the increased capabilities that it provides, use Bash and use it fully.
Nov 24, 2014 at 8:16 comment added Alastair Irvine Why are you recommending a non-portable feature when doing so gives no benefit?
Aug 5, 2014 at 14:49 history edited Dennis Williamson CC BY-SA 3.0
removed reference to zsh
Apr 5, 2013 at 10:00 comment added qed I think this is better than the accepted answer.
Sep 14, 2012 at 15:14 comment added Teemu Leisti That if [[ $variable ]] worked fine for me, and didn't even need the set -u that was required by one of the other proposed solutions.
May 23, 2012 at 21:48 history edited Dennis Williamson CC BY-SA 3.0
additional information
Feb 25, 2012 at 3:37 history answered Dennis Williamson CC BY-SA 3.0