this post was submitted on 27 Aug 2024
238 points (97.6% liked)
Programmer Humor
32495 readers
285 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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 \\\""
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 errorHere'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 notecho
ing 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 instartup-script
and must be fixed.EOF
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.And there's your problem. You're
echo
ing using double quotes which will interpret characters. Don't do that. That's a bug.cat
orcp
the file to the destination;printf
if the contents are all in that variable.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 thanecho
because its not format string, and I don't want any formatting from printf applied to it.