温馨提示×

shell怎么去除字符串的双引号

小亿
293
2023-12-12 20:01:40
栏目: 编程语言

在Shell中,可以使用${变量名//\"/}或者sed 's/\"//g'来去除字符串的双引号。

下面是一个例子:

str="\"Hello, world!\""
new_str=${str//\"/}
echo $new_str

输出结果为:

Hello, world!

或者使用sed命令:

str="\"Hello, world!\""
new_str=$(echo $str | sed 's/\"//g')
echo $new_str

输出结果也为:

Hello, world!

0