`echo "a~b" | tr '~' "=="`
这会输出a=b。但我想要a==b。如何使用tr做到这一点?
tr
只能翻译/删除字符。
尝试类似这样的东西:
echo "a~b" | sed 's/~/==/g'
你不能使用 tr
。
相反,可以使用bash字符串操作 ${string/substring/replacement}
。例如:
str="a~b"
echo ${str/"~"/"=="}
或者使用sed
:
echo "a~b" | sed 's/~/==/'
str="a~b~c"; echo ${str//"~"/==}
- user695022
b" | sed 's//&=/g'无法正常工作。我该如何处理&字符? - thetux4b" | sed 's//&=/g' - 转义它 - Prince John Wesley