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

Programmer Humor

32443 readers
807 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
top 25 comments
sorted by: hot top controversial new old
[–] listless@lemmy.cringecollective.io 24 points 2 months ago (1 children)

i think the real error was that you started the echo with a double quote and ended with a single quote. had you properly wrapped it with single quotes it would have worked. even if you had escaped the double quote, there still would have been an error because you'd have a multi-line string with no ending " (the 2nd double quote was properly escaped so that would not have terminated your string)

Also, you didn't escape your slashes.

Either it should have looked like this:

echo '# FYI quotes(") must be escaped with \ like \"'

or this:

echo "# FYI quotes(\") must be escaped with \\ like \\\""

[–] aidan@lemmy.world 4 points 2 months ago* (last edited 2 months ago) (1 children)

No, because neither of those are the inputs. The input was the systemd file in the image. The whole command was not printed in the error, only surrounding context. The single-quote was indicating the ending of that context(because it was the end of the line) printed by the error.

The same thing was done with `)' on the first line of error

[–] listless@lemmy.cringecollective.io 3 points 2 months ago (1 children)

Here's what I'm reading:

startup-script line 27 threw the error.

I'm reading this and interpreting that line 27 of that script is

sudo echo "# FYI quotes(") must be escaped with \ like \"

I am confused why there is no trailing double quote, the last 3 chars should be \"" so perhaps this is a bad assumption but the best I can do with the available information.

So the fix here is to change startup-script line 27 so that you're not echoing things that might contain characters that might be interpreted by echo or your shell.

Now if startup-script is provided by your distro, there may be a reason that it's using echo, but I will tell you now whatever dipshit reason they provide they're fucking wrong because EXHIBIT A: # " fucks the script and rule 0 of linux is "don't break userspace".

Everything else allows any printable char after the # in a comment, that script is not special, comments are not to be interpreted by the program. That is a show-stopping bug in startup-script and must be fixed.

EOF

[–] aidan@lemmy.world 1 points 2 months ago (1 children)

I’m reading this and interpreting that line 27 of that script is

And your interpretation is wrong. Line 27 is actuallly

sudo echo "${server_service}" > /lib/systemd/system/server.service

${server_service} is read from the file I posted in the 2nd image. Since it was a test script I hadn't bothered implementing any escaping tools, I wanted to make sure terraform allowed this first.

[–] listless@lemmy.cringecollective.io 3 points 2 months ago* (last edited 2 months ago) (1 children)

And there's your problem. You're echoing using double quotes which will interpret characters. Don't do that. That's a bug. cat or cp the file to the destination; printf if the contents are all in that variable.

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

No, you're still misunderstanding what's being done. ${server_service} is an injected string, the string is the whole contents of the file. That file is not stored locally on the server, except through being injected here(by a terraform file template). And no, printf won't be any better than echo because its not format string, and I don't want any formatting from printf applied to it.

[–] dohpaz42@lemmy.world 19 points 2 months ago (1 children)
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 (1 children)

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 (1 children)

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 \

[–] nialv7@lemmy.world 17 points 2 months ago (2 children)

Why are you running echo with sudo? Makes no sense.

[–] ICastFist@programming.dev 18 points 2 months ago

OP is not the brightest

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

there is no purpose other than legacy of having replaced other commands

[–] eager_eagle@lemmy.world 4 points 2 months ago (1 children)

is that really a thing for unit files? Why the hell a comment needs escaping?

[–] aidan@lemmy.world 1 points 2 months ago (2 children)

To avoid having it hosted separately its injected into a shell script as a string

[–] NeatNit@discuss.tchncs.de 6 points 2 months ago (2 children)

I don't know the system in question, but it's definitely a bad design when comments need to be written with care. Either you set this up in a really wonky way, or the system you're using did and it should be fixed ASAP.

What code is in charge of injecting things into a shell script?

[–] aidan@lemmy.world 2 points 2 months ago* (last edited 2 months ago)

terraform(really is just a injection of a file() into a shell script)

[–] Smc87@lemmy.sdf.org 1 points 2 weeks ago

You haven’t met Tom. Have you even tried JDSL?

[–] lord_ryvan@ttrpg.network 2 points 2 months ago (1 children)

Did you unlike your own comment?

[–] aidan@lemmy.world 2 points 2 months ago (1 children)

I don't think I did(though sometimes I do accidentally because of the Jeroba app UX)

[–] lord_ryvan@ttrpg.network 2 points 2 months ago

Ah, I don't think I've ever had this with Jerboa... Cool to know, thanks!

[–] sunshine@lemmy.ml 2 points 2 months ago

I've gone back and forth between a common bashrc file in my Dropbox folder that is symlinked to ~/.bashrc on my devices, and one that is imported from a regular bashrc instead, and recently it ended up in a state where it accidentally tried to do both, resulting in an endless loop. I discovered this on my Pop!_OS PC, which reacted to this situation by crashing on login lol. What??

[–] bamfic@lemmy.world 2 points 2 months ago (1 children)
[–] aidan@lemmy.world 3 points 2 months ago (1 children)

I don't disagree, but this time its my fault

[–] vext01@lemmy.sdf.org 2 points 2 months ago

It's a really silly requirement IMHO.