Escaping pipe character in rsh

kirbo picture kirbo · Mar 30, 2013 · Viewed 16.1k times · Source

I am trying to run this bash command, but I cant get around the "|" pipe character

rsh -l user machine "echo "PORTS = 123|456|789" >> conf.cfg"

Getting:

bash: 456 >> conf.cfg: No such file or directory

bash: 789: command not found

Would you know how I can echo PORTS = 123|456|789 into a remote file ?

Thanks!

Answer

fedorqui 'SO stop harming' picture fedorqui 'SO stop harming' · Mar 30, 2013

Just escape the pipes and the quotes:

rsh -l user machine "echo \"PORTS = 123\|456\|789\" >> conf.cfg"