先把答案给你。
如果是在脚本里写的话,先把extended patter matching打开
shopt -s extglob
for i in $(cat temp) #这里假设temp是楼主放数据的文件
do
i=${i##*(0)}
echo $i
done
就可以将前面的0全删掉了。至于为什么,建议楼主man bash以下。
然后在1062-1092行中间,这么说的
${parameter##word}
Remove matching prefix pattern. The word is expanded to produce a pattern just as in pathname expansion.
在parameter expansion(参数展开)中,知道${parameter##word}中的word是按照pathname expansion进行的,不是正则表达式(grep)类型的,所以不能在后面加*来实现匹配0到无穷次。
pathname expansion在bash的手册里也有, 1229-1259行中提到
If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are rec‐
ognized. In the following description, a pattern-list is a list of one or more patterns separated by a |. Compos‐
ite patterns may be formed using one or more of the following sub-patterns:
?(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
所以这里,我用*(0)就可以匹配任意次0了