我想在变量赋值行的 bash 中使用正则表达式
例如
oldip="14\.130\.31\.172"
oldip_a="14.130.31.172" //How to use regex on this line.
如何使用正则表达式删除$oldip中的所有'\'?然后给 $oldip_a 赋新值。
你有什么想法吗?
最佳答案
我相信你想像这样使用字符串替换:
oldip_a=${oldip//\\/}
或者类似的东西......当然总是有一些逃避反斜杠的战斗!
一个更明显的例子:
some_variable=${some_other_variable//replaceEachOfThese/withThis}
在此页面上搜索“替换所有匹配项”:
http://tldp.org/LDP/abs/html/string-manipulation.html
关于bash - 如何使用正则表达式(bash)为变量赋值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9696719/