239
submitted 2 months ago by aidan@lemmy.world to c/programmerhumor@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments
[-] dohpaz42@lemmy.world 19 points 2 months ago
sudo echo "# FYI quotes(") must be escaped with \ like \"

👆 that is not a comment. That is a command that says to echo the text "# FYI quotes(" and then to do ) must be escaped like \ \" which is invalid syntax.

I assume that startup script is reading the contents of the file and trying to echo them into another file? i.e., using the original file as a template, but is not escaping the input, hence the error — which you’re lucky that’s the problem you’re encountering and not something actually destructive like sudo echo "# foo" && rm -rf /*.

[-] aidan@lemmy.world 2 points 2 months ago

dsygraphia, I meant to say escape the quotes(you can see that because the comment wasn't about comments but was instead about quotes)

[-] dohpaz42@lemmy.world 3 points 2 months ago

It’s all good. If you’re using bash and readline to read the file, you can use sudo echo ${INPUT@Q} (assuming your variable is named $INPUT) to have bash escape things like the quotes and other characters that could get you into trouble.

[-] aidan@lemmy.world 1 points 2 months ago

Sadly no, its injected with terraform templatefile, I already looked for a normal way to autoescape it, but from a brief look I couldn't find one. I know there is a replace function that can take regex(RE2, which from my understanding prohibits * in lookbehinds)- but the simplest regex I could think of at nearly 6am for capturing only non-escaped quotes is /(?:^|[^\\])(?:(?:\\\\)+|[^\\]|^)(?'quote'")/gm. Though, I just realized if the quotes are escaped I would want to double escape them, so actually replacing all quotes with escaped quotes should be fine, also another limitation of this method is lines can't have trailing \

this post was submitted on 27 Aug 2024
239 points (98.4% liked)

Programmer Humor

32410 readers
465 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS