我需要在unix中显示类似今天"程序" 的字符串作为输出。但是,如果我给出以下没有选项正在运作。
>echo "Today's "program""
Today's program
> echo "Today\'s "program""
Today\'s program
> echo 'Today's "program"'
>
echo 'Today\'s "program"'
>
答案 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。