Timeline for How can I declare and use Boolean variables in a shell script?
Current License: CC BY-SA 4.0
28 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 19 at 18:26 | history | edited | wjandrea | CC BY-SA 4.0 |
Improve formatting of cases - numbered list instead of code block. Unless I'm horribly mistaken, `var=` is equivalent to `var=""`.
|
Nov 24, 2021 at 5:36 | comment | added | Teocci |
I usually use this way: a=true and I evaluate like this if [ "$a" = 'true' ]; then . In our recommendation you used if [ "$my_bool" = true ]; then and if [ "$my_bool" = "true" ]; then It is my way wrong? why you didn't use simple quotes 'true' but double quotes "true" ?
|
|
Apr 8, 2021 at 13:43 | history | edited | einpoklum | CC BY-SA 4.0 |
Better distinguishing the variable name from the name of the type. It's confusing when the variable name is the same as the name of a type in some programming languages.
|
Mar 29, 2021 at 20:11 | comment | added | Bill Gale | @Dennis Since the OP also wanted to check for false, it would be helpful for this highly rated answer to present recommended ways to test for false, rather than just use an example with false to blow up another answer here. | |
S Aug 17, 2020 at 3:36 | history | edited | tgdavies | CC BY-SA 4.0 |
Changed Grammar mistakes and comment positioning
|
S Aug 17, 2020 at 3:36 | history | suggested | Saiansh Singh | CC BY-SA 4.0 |
Changed Grammar mistakes and comment positioning
|
Aug 16, 2020 at 1:32 | review | Suggested edits | |||
S Aug 17, 2020 at 3:36 | |||||
Jan 1, 2020 at 12:26 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Used a more direct cross reference, etc.
|
Jan 1, 2020 at 12:20 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Active reading [<https://en.wiktionary.org/wiki/Boolean#Noun>].
|
Oct 24, 2019 at 17:07 | history | rollback | Dennis |
Rollback to Revision 8
|
|
Oct 23, 2019 at 12:07 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Active reading [<https://en.wiktionary.org/wiki/Boolean#Noun>].
|
Sep 9, 2019 at 17:09 | comment | added | matanox |
Worth noting that equality evaluates to 1 and so these conditions actually check the opposite of what they would in most other programming languages?
|
|
May 9, 2019 at 15:21 | comment | added | San | Answers like these and Contributors like you make Stack Overflow the best place for devs. Thank you! | |
May 3, 2018 at 15:14 | history | edited | Vadim Kotov | CC BY-SA 4.0 |
fixed formatting
|
May 23, 2017 at 10:31 | history | edited | URL Rewriter Bot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
Mar 4, 2016 at 14:34 | comment | added | Dennis | @dolmen absolutely, evaluating input isn't as risky when you control the input, but I still consider it a bad practice that should be avoided if it can easily be avoided. Someone who has only ever seen and used the former style may not know about its flaws which can cause unexpected behaviour. | |
Mar 4, 2016 at 13:40 | comment | added | dolmen |
If var is a local variable where assignments are completely controlled in your program, there is no risk in using @miku's answer without quotes.
|
|
Jun 9, 2015 at 23:54 | comment | added | wisbucky | For me, conceptually it is easier to understand if I use bool="true". Then it's clear that it's just a string and not some special value or builtin. | |
Feb 26, 2015 at 22:56 | history | edited | Dennis | CC BY-SA 3.0 |
added 39 characters in body; added 5 characters in body
|
Jan 20, 2015 at 17:01 | comment | added | Kranach | Yeah, I just couldn't find in comments any appreciation for this hidden joke, so had to point it out =) | |
Jan 20, 2015 at 16:40 | comment | added | Dennis |
@Kranach that's expected output and what I consider a valid command even though the man command is used incorrectly. If it were invalid, you would see man: command not found . That's what I mean with footnote #3. (Edit: Posted this before I saw your edit :))
|
|
Jan 11, 2015 at 5:10 | comment | added | Dennis | @Scott I use fish as my primary shell, which has a sane scripting language compared to bash in my opinion. | |
Apr 30, 2014 at 15:55 | history | edited | chepner | CC BY-SA 3.0 |
deleted 142 characters in body
|
Apr 30, 2014 at 12:29 | comment | added | chepner |
Using == with [ or test is not portable. Considering portability is the only advantage [ /test has over [[ , stick with = .
|
|
Feb 19, 2014 at 20:35 | history | edited | Dennis | CC BY-SA 3.0 |
Link to Mike Holt's explanation of Miku's answer
|
Jan 19, 2014 at 4:40 | history | edited | Dennis | CC BY-SA 3.0 |
Point out issues in Hbar's answer
|
Jan 19, 2014 at 2:42 | history | edited | Dennis | CC BY-SA 3.0 |
Be a bit more specific.
|
Jan 18, 2014 at 22:57 | history | answered | Dennis | CC BY-SA 3.0 |