Escaping quotes, sudo """ '

1,641 views
Skip to first unread message

Jakub Muszynski

unread,
Dec 18, 2015, 10:48:25 AM12/18/15
to rundeck-discuss
Those (simplified) commands work in bash:
  • sudo su - ansible bash -c "ANSIBLE_FORCE_COLOR=true; echo '{\"versions\":{\"campaigns_manager\":\"0.9.310\"}}' "
  • sudo su - ansible bash -c """ANSIBLE_FORCE_COLOR=true; echo  '{\"versions\":{\"campaigns_manager\":\"0.9.310\"}}' """
    • {"versions":{"campaigns_manager":"0.9.310"}}

If placed them in the rundeck command, then:
  • sudo su - ansible bash -c "ANSIBLE_FORCE_COLOR=true; echo '{\"versions\":{\"campaigns_manager\":\"0.9.310\"}}' "
    • Fails to execute at all (fails around the export command)
  • sudo su - ansible bash -c """ANSIBLE_FORCE_COLOR=true; echo  '{\"versions\":{\"campaigns_manager\":\"0.9.310\"}}' """
    • Runs but produces:
      • {\versions\:{\campaigns_manager\:\0.9.310\}}
    • does remove double-quotes that leads to 
      • ERROR: Expecting property name enclosed in double quotes: line 1 column 2 (char 1
    • expected result:
      • '{"versions":{"campaigns_manager":"0.9.310"}}'
  • additionaly, following command:
    • sudo su - ansible bash -c """ANSIBLE_FORCE_COLOR=true; echo '{"versions":{"campaigns_manager":"0.9.310"}}' """
      • evaluates to
        • {versions:{campaigns_manager:0.9.310}}
I need to pass the JSON
Any way of keeping double-quotes in the executed shell command?


Alternatively - I could try to switch :
  • sudo su - ansible bash -c """ something """
    • to
  • sudo su - ansible bash -c " something "
If You know how to do escaping only with double+single quotes, when _inside_ of the command (that is marked by single or double quotes), You need to use a combination of the two (singe and double quotes)
  • sudo su - ansible bash -c " something; echo '{"versions":{"campaigns_manager":"0.9.310"}}' "
In case You were wanderring, the full command to run looks like:

sudo su - ansible bash -c "export ANSIBLE_FORCE_COLOR=true; cd ~/ansible; source ~/ansible/environment.sh; ansible-playbook -i ~/ansible/etc/inv/inventory ~/ansible/etc/playbooks/run_server.yml -e '{"versions":{"manaegr":"0.9.3"}}' --check --diff -v"

Alex Honor

unread,
Dec 18, 2015, 12:33:37 PM12/18/15
to rundeck...@googlegroups.com
Hi Jakub,

When quoting becomes necessary I generally use a script step to keep it easier to maintain.

Thanks

--
You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/4800a1c0-ac79-46b2-a9ce-e4c7ab190022%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Alex Honor

[SimplifyOps, Inc | a...@simplifyops.com ]

Be sure to comment and vote on Rundeck Feature Development!

Reply all
Reply to author
Forward
0 new messages