• listless@lemmy.cringecollective.io
    link
    fedilink
    arrow-up
    21
    ·
    2 months 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 \\\""

    • aidan@lemmy.worldOP
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      2 months 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

      • listless@lemmy.cringecollective.io
        link
        fedilink
        arrow-up
        3
        ·
        2 months 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

        • aidan@lemmy.worldOP
          link
          fedilink
          arrow-up
          1
          ·
          2 months 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.

          • listless@lemmy.cringecollective.io
            link
            fedilink
            arrow-up
            3
            ·
            edit-2
            2 months 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.

            • aidan@lemmy.worldOP
              link
              fedilink
              arrow-up
              1
              ·
              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
    link
    fedilink
    English
    arrow-up
    18
    arrow-down
    1
    ·
    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.worldOP
      link
      fedilink
      arrow-up
      2
      ·
      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
        link
        fedilink
        English
        arrow-up
        3
        ·
        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.worldOP
          link
          fedilink
          arrow-up
          1
          ·
          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 \

    • aidan@lemmy.worldOP
      link
      fedilink
      arrow-up
      1
      ·
      2 months ago

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

      • NeatNit@discuss.tchncs.de
        link
        fedilink
        arrow-up
        5
        ·
        2 months 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?

  • sunshine@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    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??