我有我正经过值bash脚本 - 查找替换多个值
我要剥去传递给脚本值前缀一个非常简单的bash脚本。
从传递价值的作品和带test-
..
IN=$1
arrIN=(${IN//test-/})
echo $arrIN
所以测试12345 12345返回
反正是有修改这一所以它会删除或者test-
或local-
?
我已经试过:
arrIN=(${IN//test-|local-/})
但是,这并不会工作。
感谢
我有我正经过值bash脚本 - 查找替换多个值
我要剥去传递给脚本值前缀一个非常简单的bash脚本。
从传递价值的作品和带test-
..
IN=$1
arrIN=(${IN//test-/})
echo $arrIN
所以测试12345 12345返回
反正是有修改这一所以它会删除或者test-
或local-
?
我已经试过:
arrIN=(${IN//test-|local-/})
但是,这并不会工作。
感谢
如果你想改变 “测试 - ” 或 “局地” 到 “” ,你可以使用如下命令:
awk '{gsub(/test-|local-/, ""); print}'
您可以使用sed
,并得到确切的结果
IN=$1
arrIN=$(echo $IN | sed 's/[^-]\+.//')
echo $arrIN
你可以用extglob
激活做到这一点:
shopt -s extglob
arrIN=(${IN//+(test-|local-)/})
从man bash:
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
'$ {VAR ## * - }'从去年得到部分'-'来字符串的结尾。但是你正在使用数组符号,所以目前还不清楚这是否足够/ – fedorqui 2014-12-03 12:42:16