What is the most aesthetic way to to escape a single quote within a single-quoted string in (ba)sh?

前端 未结 5 1337
予麋鹿
予麋鹿 2021-01-26 06:23

In a (ba)sh script of mine, I have, for example:

MYVAR=\'Alice says: \"Hello, Bob.\" But Bob isn\'t listening.\'

This is a syntax error, since

5条回答
  •  滥情空心
    2021-01-26 07:06

    You could also use double quotes and escaping. I guess, it is simpler than change the language:

    MYVAR="Alice says: \"Hello, Bob.\" But Bob isn't listening."
    

    More information about escaping symbols in bash.

提交回复
热议问题