1

I am trying to write a script which has to execute a command containing single quotes in it. This is the command I am trying to execute in the script:

srt-live-transmit udp://224.0.0.0:1234 'srt://@1111?passphrase=thisisatest&latency=500' -v

And this is my BASH shell script's command:

srt-live-transmit $MC srt://${SRT_IP}:${SRT_PORT}?${LATENCY}&${PASS} -v

As you can see the SRT path is in single quotes in order for the command to accept my both parameters: passphrase and latency. I have tried to escape the single quote with \', '\'', '"'"', $\' but the command is either not executed or the SRT path is without single quotes when I grep for the process in the process list.

8
  • 5
    "nothing seemed to work" ... what error message do you get? What is the actual issue here?
    – Panki
    Sep 10 '19 at 8:41
  • it just my command is either not executed or the SRT path is without the single quotes. Sep 10 '19 at 8:43
  • @GeorgеStoyanov why? I mean, why don't you run the command exactly as you show it? Why is any escaping needed? Is that command in a variable or is it just a line in your script?
    – terdon
    Sep 10 '19 at 8:46
  • 2
    Why do you think that you need to pass the literal single quotes to the srt-live-transmit command? Yes, you need to use quotes to protect the & from the shell, but that's that. The shell will remove the single quotes from the argument once it is parsed, just as in echo 'hello & goodbye'. Your command, as written, ought to work. Please explain what does not work.
    – Kusalananda
    Sep 10 '19 at 8:46
  • "when I grep for the process in the process list" ... when you run some-command 'foo-bar', the shell removes the quotes. They won't show up in the process list.
    – muru
    Sep 10 '19 at 8:50
2

If I understand correctly, and your variables contain what I guess they contain (next time, please show us what the variables' values are and how you assign them), then all you need is quoting:

srt-live-transmit "$MC" "srt://${SRT_IP}:${SRT_PORT}?${LATENCY}&${PASS}" -v

You can't really escape single quotes in a single-quoted string, but you can just use double quotes, which allow variables to be expanded, instead.

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.