How do you avoid a tricky G string?

I want to use Salt States to change PROMPT_COMMAND

systems on a network, but I was unable to figure out the correct string escaping strategy. Prompt command:

PROMPT_COMMAND='PS1="`if [[ \$? -eq "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi`\! \[\033[36m\]\u@\h \[\033[33m\]\W \[\033[0m\]$ "'

      

First I tried:

/etc/bash.bashrc:
  file.append:
    - text:
      - PROMPT_COMMAND='PS1="`if [[ \$? -eq "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi`\! \[\033[36m\]\u@\h \[\033[33m\]\W \[\033[0m\]$ "'

      

But the state won't compile. I tried two more times (once with single quotes and again with double quotes) quoting the string and avoiding nested instances inside. Nothing worked. Then I put the directive in a text file ( bashrc.txt

) and tried:

/etc/bash.bashrc:
  file.append:
    - source: salt://_fragments/bashrc.txt

      

But it also ruins the rendering system, although you will notice that I purposefully omit the argument - template: jinja

.


Is there some other escaping mechanism available via Salt or Jinja that will resist the many nested ticks, quotes, and backslashes present in this particularly awful line?

+3


source to share


1 answer


Have you tried this?



/etc/bash.bashrc:
  file.append:
    - text: |
        PROMPT_COMMAND='PS1="`if [[ \$? -eq "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi`\! \[\033[36m\]\u@\h \[\033[33m\]\W \[\033[0m\]$ "'

      

+3


source







All Articles