bash 如何在bash中转义双引号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35586627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:17:40 来源:igfitidea点击:
How to escape double quotes in bash?
提问by neo33
I want to escape double quotes in bash, I followed the following approach:
我想在 bash 中转义双引号,我遵循了以下方法:
#!/bin/bash
this is a \"number\"!
but i need to know if there is another way.
但我需要知道是否有另一种方式。
回答by Dirk Herrmann
You can enclose the double quotes in single quotes:
您可以将双引号括在单引号中:
echo '"'hola'"'
or alternativela the whole text, including the double quotes:
或替代整个文本,包括双引号:
echo '"hola"'
回答by Cyrus
With GNU bash:
使用 GNU bash:
echo -e "this is a \x22number\x22"
Output:
输出:
this is a "number"