Timeline for Why are ASCII escape sequences for ' treated differently in grep/sed/awk?
Current License: CC BY-SA 4.0
31 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 16, 2024 at 18:35 | comment | added | Stéphane Chazelas | @jrw32982 I do mention it already here: also found in perl since perl 4; one of the earliest tools to support it (and \x{ffff...} before C added \uFFFF I believe which I mention as well). | |
| Dec 16, 2024 at 18:06 | comment | added | jrw32982 | Stéphane and I have had this conversation before, but "\x27" is also valid in perl, which is where I use it for this kind of thing: BEGIN { $q = "\x27" } | |
| Dec 9, 2024 at 8:46 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 42 characters in body |
| Dec 9, 2024 at 8:23 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 136 characters in body |
| Dec 9, 2024 at 7:30 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 149 characters in body |
| Dec 9, 2024 at 7:08 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 220 characters in body |
| Dec 9, 2024 at 6:55 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 220 characters in body |
| Dec 9, 2024 at 6:39 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 67 characters in body |
| Dec 8, 2024 at 20:43 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 323 characters in body |
| Dec 8, 2024 at 15:15 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 139 characters in body |
| Dec 8, 2024 at 14:14 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 126 characters in body |
| Dec 8, 2024 at 11:24 | vote | accept | Ed Morton | ||
| Dec 8, 2024 at 8:36 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 4 characters in body |
| Dec 7, 2024 at 22:29 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 422 characters in body |
| Dec 7, 2024 at 21:14 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 66 characters in body |
| Dec 7, 2024 at 20:36 | comment | added | Ed Morton | You're right, I got it backwards (been doing that all day and correcting!). Thanks for confirming. | |
| Dec 7, 2024 at 20:02 | comment | added | Stéphane Chazelas | @EdMorton, that's the other way round \x27 is not defined for anything other than $'...', \47 for C, awk, printf format (both of which are shaped after C), and \047 for echo and printf's %b. | |
| Dec 7, 2024 at 19:10 | comment | added | Ed Morton | So.... after doing some wading through POSIX and reading your answer, am I right in thinking that \027 and \27 are both undefined behavior per POSIX for all 3 of grep, sed and awk and that \x47 is defined by POSIX for awk but undefined for grep and sed? I added the standards references to the bottom of my question, if you know of anywhere else in POSIX that those escape sequences are defined for those tools, please let me know. | |
| Dec 7, 2024 at 18:14 | comment | added | Ed Morton | Regarding awk_code=$(here doc); awk "$awk_code" - I think that's the first time I've seen awk code stored in a variable where it was a useful thing to do. Until now I've thought it was just to help syntax highlighting of shell scripts in some editors. | |
| Dec 7, 2024 at 18:03 | comment | added | Ed Morton | Then I'd have to do printf '%q' or something to go the other way. Copy/paste is simpler and \047 works in both contexts. | |
| Dec 7, 2024 at 18:01 | comment | added | Stéphane Chazelas | @EdMorton, you can always replace awk with printf '%s\n' > file.awk to store that awk code, same as you'd do for sh, sed code or anything else. | |
| Dec 7, 2024 at 18:00 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 108 characters in body |
| Dec 7, 2024 at 17:59 | comment | added | Ed Morton | I'm not sure what you mean. I'll fairly often start writing a script (actually a utility awk function) as awk 'BEGIN{print "It\047s not pretty"}' and then as it grows decide I should move it to a file foo.awk containing BEGIN{print "It\047s not pretty"} to execute as awk -f foo.awk or vice-versa. If my starting point was instead awk 'BEGIN{print "It'\''s not pretty"}' then I couldn't save BEGIN{print "It'\''s not pretty"} to a file foo.awk and execute it as awk -f foo.awk. | |
| Dec 7, 2024 at 17:21 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 646 characters in body |
| Dec 7, 2024 at 15:59 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 5 characters in body |
| Dec 7, 2024 at 15:50 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 5 characters in body |
| Dec 7, 2024 at 15:48 | comment | added | Stéphane Chazelas | @EdMorton, in what sort of context would that be an actual problem? It's the same in sh -c 'echo "It'\''s not pretty, but it works"' vs having echo "It's not pretty, but it works" in a shell script. | |
| Dec 7, 2024 at 15:44 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 191 characters in body |
| Dec 7, 2024 at 15:41 | comment | added | Ed Morton | Thanks for the answer, I'll read it in detail a little later but regarding "In any case for ' specifically, there's no need to specify the point code, as $'\'' works." - I use \047 in my scripts so they will work whether I use them from the command line as awk 'foo \047 bar' or stored in a file as awk -f scriptfile and you can't do that if you write the script as foo '\'' bar instead. | |
| Dec 7, 2024 at 15:36 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 191 characters in body |
| Dec 7, 2024 at 15:30 | history | answered | Stéphane Chazelas | CC BY-SA 4.0 |