0

I have some really long and complex command containing both types of quotes: " and ', for example like:

cd folder && command --hel="p_me:'please' anyone:'here?'" ; command2 --end='my:"trouble"'

I want to throw it into the echo command. But it does not work easily, I have to insert it into another quotes and escape some quotes inside the command. This should be okay usually, but unfortunately this time I can not change the command itself (and escape any quotes inside).

How to echo a command containing both types of quotes without its modification? How to escape the quotes on-run for echo?

  • Why do you need to echo this? What's the goal? – muru Aug 7 '18 at 6:45
  • It is not the echo exactly, I have to pass the command to the cron's jsub command, but it pretty much behaves the same way as echo does when interpreting its input – aleskva Aug 7 '18 at 6:46
  • 1
    Cron's jsub command? What exactly do you mean? Which cron? Please show what you're actually trying to do. echo foo prints foo, and there are any number of ways to print foo (i.e., do what echo does), but if you're using some other command, not all of those ways will be applicable to you. – muru Aug 7 '18 at 6:49
  • The whole line is jsub -N cron-89 -once -quiet foo (where foo is my command). But the interpretation of my command works the same way as echo does, it strips the outer quotes (if not escaped), but this time I can not escape them before unfortunately – aleskva Aug 7 '18 at 6:52
  • 1
    you should use cd folder && { command ...; command2 ...; }. Otherwise command2 will be executed even when cd folder fails. .... Anyways, I feel like this is an XY-Problem – pLumo Aug 7 '18 at 7:06
0

You could use a heredoc:

xargs -d $'\n' echo <<'EOF'
cd folder && command --hel="p_me:'please' anyone:'here?'" ; command2 --end='my:"trouble"'
EOF

Example:

$ xargs -d $'\n' echo <<'EOF'
cd folder && command --hel="p_me:'please' anyone:'here?'" ; command2 --end='my:"trouble"'
EOF

cd folder && command --hel="p_me:'please' anyone:'here?'" ; command2 --end='my:"trouble"'

I don't know what jsub is and I couldn't find it in the repositories for 14.04, but unless it runs a shell or can interpret shell syntax, I don't think this will work the way you think it will.

xargs -d $'\n' jsub -N cron-89 -once -quiet <<'EOF'
cd folder && command --hel="p_me:'please' anyone:'here?'" ; command2 --end='my:"trouble"'
EOF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.