有时我想在Git提交信息中添加更多的表达性,但很遗憾,Bash似乎不支持这样做。
iblue@silence ~/git/wargames $ git commit -m "Frustrating <insert object of frustration here>!"
-bash: !": event not found
使用反斜杠进行转义可以解决问题,但是这样会将反斜杠包含在提交的信息中。
如何正确地在bash中转义感叹号?
有时我想在Git提交信息中添加更多的表达性,但很遗憾,Bash似乎不支持这样做。
iblue@silence ~/git/wargames $ git commit -m "Frustrating <insert object of frustration here>!"
-bash: !": event not found
使用反斜杠进行转义可以解决问题,但是这样会将反斜杠包含在提交的信息中。
如何正确地在bash中转义感叹号?
在单引号字符串中,感叹号会被按照字面意义保留。
例如:
git commit -m 'Frustrating <insert object of frustration here>!'
试试这个
git commit -m "令人沮丧的 <插入沮丧对象>"'!'
如果在字符串中间,则
"你好"'!'"世界"
使用单引号而不是双引号可以防止扩展。
" ' ! ' "
(不包括我添加的空格)来将其分离。 - ignacio\
来转义它。即:
git commit -m "Frustrating <insert object of frustration here>\!"
然而,我个人建议您通过将 set +H
或 set +o histexpand
添加到您的 .bashrc
文件来禁用 bash 扩展。grep
时尝试在双引号字符串中使用\
转义!
,但它对我没有起作用,我已确认它失败的原因与OP相同。 - AJM