linux - 如何在 Bash 中的单引号字符串中转义单引号?

标签 linux bash escaping

我想像这样在 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/

相关文章:

unicode - 什么是转义字符\u000a

python - 单引号字符串与双引号字符串

linux - 如何通过ftp部署nginx?

regex - Grep for <?php 空行后

linux - 发送电子邮件和通知发送在 crontab 中不起作用

bash - while循环BASH中的语法错误

linux - while 循环不遍历文件

linux - 如何列出随机文件夹下的文件大小?

php - 如何使用 PHP 设置 Beanstalkd

sql - 在 Rails 中转义 SQL LIKE 查询