Timeline for How can I prevent unsupported 'shopt' options from causing errors in my .bashrc?
Current License: CC BY-SA 4.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 4, 2020 at 15:19 | comment | added | Kevin E | @DavidFoerster Good eye. I had never scrutinized the output of help shopt that closely before, but I think you need to leave out the -o which restricts the output to options "defined for use with set -o"—which direxpand is not. A shame the return value of shopt is non-zero for both unset and invalid options, otherwise -q (suppress output) could've also come in handy. | |
| Aug 4, 2020 at 15:15 | review | Suggested edits | |||
| Aug 4, 2020 at 18:07 | |||||
| Feb 7, 2019 at 18:07 | comment | added | David Foerster | @Rich: Most of my shell scripts include set -e at the top, so I tend to use short-cut logic this way around. | |
| Feb 6, 2019 at 16:47 | comment | added | Rich | @DavidFoerster I'd turn the logic around: [ -n "blah" ] && shopt blah The way you phrase it, you're saying "if direxpand is unsupported, then don't do this thing". | |
| Feb 5, 2019 at 21:47 | comment | added | David Foerster | Bash allows to query specific shell options, so one can use [ -z "$(shopt -po direxpand 2>&-)" ] || shopt -s direxpand. No more regex issues! :-) | |
| Feb 5, 2019 at 18:21 | vote | accept | Kevin E | ||
| S Feb 5, 2019 at 18:12 | history | suggested | Kevin E | CC BY-SA 4.0 | Match on a word boundary as proposed by Gilles |
| Feb 5, 2019 at 18:05 | comment | added | Kevin E | Thanks Luciano. I'd intended to answer my own question, but I"ll accept your answer after my edits go through peer review. Maybe you can approve them yourself? | |
| Feb 5, 2019 at 18:04 | review | Suggested edits | |||
| S Feb 5, 2019 at 18:12 | |||||
| Feb 5, 2019 at 17:45 | comment | added | Gilles 'SO- stop being evil' | Better make that grep -q '^direxpand\b' in case some future version or fork of bash has an option that contains this as a substring and removes direxpand. Unlikely in this specific case, but it doesn't cost much to be robust. | |
| Feb 5, 2019 at 17:30 | history | edited | Luciano Andress Martini | CC BY-SA 4.0 | added 3 characters in body |
| Feb 5, 2019 at 17:23 | history | answered | Luciano Andress Martini | CC BY-SA 4.0 |