How do I use single quotes inside single quotes?

前端 未结 7 2005
梦谈多话
梦谈多话 2020-12-31 14:10

Can anyone explain how to make this code work?

echo \'
Welcome
\'
7条回答
  •  醉话见心
    2020-12-31 14:37

    Inside single quotes, variable names aren't parsed like they are inside double-quotes. If you want to use single-quoted strings here, you'll need to use the string concatenation operator, .:

    echo '
    Welcome
    ';

    By the way: the answer to the question in the title is that in order to use a literal single-quote inside a single-quoted string, you escape the single-quote using a backslash:

    echo 'Here is a single-quote: \'';
    

提交回复
热议问题