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??
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
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.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.
Fucking systemd istg
I don’t disagree, but this time its my fault
It’s a really silly requirement IMHO.
is that really a thing for unit files? Why the hell a comment needs escaping?
To avoid having it hosted separately its injected into a shell script as a string
Did you unlike your own comment?
I don’t think I did(though sometimes I do accidentally because of the Jeroba app UX)
Ah, I don’t think I’ve ever had this with Jerboa… Cool to know, thanks!
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?
terraform(really is just a injection of a file() into a shell script)
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 /*
.dsygraphia, I meant to say escape the quotes(you can see that because the comment wasn’t about comments but was instead about quotes)
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.
Why are you running echo with sudo? Makes no sense.
OP is not the brightest
there is no purpose other than legacy of having replaced other commands