扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

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

扬州沐宇科技
2023-12-12 20:01:40
shell

在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!

扫码添加客服微信