如何在unix中的echo中显示单引号和双引号

时间:2017-11-15 13:56:45

标签: bash unix

我需要在unix中显示类似今天"程序" 的字符串作为输出。但是,如果我给出以下没有选项正在运作。

>echo "Today's "program""
Today's program

> echo "Today\'s "program""
Today\'s program

> echo 'Today's "program"'
>

echo 'Today\'s "program"'
>

3 个答案:

答案 0 :(得分:3)

如果要在双引号内显示​​双引号,则必须转义它们:

$> echo "today's \"program\""
today's "program"

您还可以连接引用的字符串:

$> echo 'today'"'"'s "program"'
today's "program"

或者只是逃避它们:

$> echo today\'s \"program\"
today's "program"

答案 1 :(得分:1)

> echo 'Today'\''s "program"'
Today's "program"

答案 2 :(得分:1)

多种可能性:

> echo 'Today'"'"'s "program"'
Today's "program"
> echo Today"'"s '"program"'
Today's "program"
> echo Today\'s '"program"'
Today's "program"
> echo Today\'s \"program\"
Today's "program"

有关这三种逃避的区别,请参阅this article