• @[email protected]
    link
    fedilink
    2419 days ago

    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 \\\""

    • @aidanOP
      link
      4
      edit-2
      19 days ago

      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

      • @[email protected]
        link
        fedilink
        317 days ago

        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

        • @aidanOP
          link
          117 days ago

          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.

          • @[email protected]
            link
            fedilink
            2
            edit-2
            17 days ago

            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.

            • @aidanOP
              link
              117 days 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
    link
    English
    2019 days 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 /*.

    • @aidanOP
      link
      219 days 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
        link
        English
        319 days 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.

        • @aidanOP
          link
          119 days 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
    link
    1818 days ago

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

    • @aidanOP
      link
      218 days ago

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

  • Eager Eagle
    link
    English
    519 days ago

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

    • @aidanOP
      link
      119 days ago

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

      • @[email protected]
        link
        fedilink
        619 days ago

        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?

        • @aidanOP
          link
          2
          edit-2
          19 days ago

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

        • @aidanOP
          link
          219 days ago

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

          • Fonzie!
            link
            fedilink
            219 days ago

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

  • @[email protected]
    link
    fedilink
    212 days 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
    link
    English
    219 days ago

    Fucking systemd istg