Timeline for How does storing the regular expression in a shell variable avoid problems with quoting characters that are special to the shell?
Current License: CC BY-SA 4.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 2, 2024 at 6:34 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
added 846 characters in body
|
| Oct 19, 2018 at 13:54 | comment | added | Matt |
Your $regexp should *not* be quoted. line is worth its weight in gold. Thanks!
|
|
| Jul 28, 2017 at 11:25 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
edited body
|
| Jul 28, 2017 at 11:17 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 171 characters in body
|
| Jul 27, 2017 at 21:31 | comment | added | Tim |
[[ $a = a|b ]] results in syntax error in conditional expression: unexpected token '|', while regexp='a|b'; [[ $a = $regexp ]] doesn't. Why is the difference? Does parameter expansion of regexp delay a|b's appearing in the conditional expression, so that the delay can avoid some interpretation step which reports error on [[ $a = a|b ]]? What interpretation step is that?
|
|
| Jul 27, 2017 at 21:25 | comment | added | Tim |
[[ $a =~ a|b ]] works with | being interpreted as OR in regex. In the approach of using a variable, the same regex is assigned to the variable regexp='a|b'. So the example doesn't seem to show that the variable approach avoids problems with quoting characters. However, the variable approach does make a difference when =~ for regex is replaced with = for globbing.
|
|
| Jul 27, 2017 at 13:49 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 163 characters in body
|
| Jul 27, 2017 at 13:43 | history | answered | Stéphane Chazelas | CC BY-SA 3.0 |