我想像这样在 Bash 中显示一个字符串
I'm a student
当然可以这样
echo "I'm a student"
但是如何在字符串周围使用单引号来实现这一点?
最佳答案
echo 'I\'m a student'
不起作用。但以下工作:
echo $'I\'m a student'
来自 bash 的手册页:
A single quote may not occur between single quotes, even when preceded by a backslash.
....
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.
关于linux - 如何在 Bash 中的单引号字符串中转义单引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8254120/