How to escape the single quote character in an ssh / remote bash command?

前端 未结 5 2147
春和景丽
春和景丽 2020-12-01 07:51

I\'m building a small set of scripts for remotely starting, stopping and checking the status of a process. The stop of these scripts should look for a process a

5条回答
  •  盖世英雄少女心
    2020-12-01 08:25

    This is not ssh or awk handling the quotes, it is the shell (and they are necessary to keep the shell from handling other characters specially, like $). Nesting them is not supported (although other structures, such as $() may nest even while containing quotes), so you'll need to escape the single quotes separately. Here are a couple of methods:

    $ echo 'Don'"'"'t mess with this apostrophe!'
    Don't mess with this apostrophe!
    $ echo 'Don'\''t mess with this apostrophe!'
    Don't mess with this apostrophe!
    

提交回复
热议问题