bash for循环中的Access*
我有这样一个bash for循环:bash for循环中的Access*,bash,Bash,我有这样一个bash for循环: for i in /long/path/filename*; do echo ${i%filename*}/other/path/c01/{magic}; done for i in /long/path/filename*; do A=${i/\/long\/path\/filename/} echo ${i%filename*}/other/path/c01/${A} done 现在我想用*匹配的文本替换{magic},可能是
for i in /long/path/filename*; do
echo ${i%filename*}/other/path/c01/{magic};
done
for i in /long/path/filename*; do
A=${i/\/long\/path\/filename/}
echo ${i%filename*}/other/path/c01/${A}
done
现在我想用*匹配的文本替换{magic},可能是这样的:
for i in /long/path/filename*; do
echo ${i%filename*}/other/path/c01/{magic};
done
for i in /long/path/filename*; do
A=${i/\/long\/path\/filename/}
echo ${i%filename*}/other/path/c01/${A}
done
从
manbash
:
${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in pathname
expansion. If the pattern matches the beginning of the value of
parameter, then the result of the expansion is the expanded
value of parameter with the shortest matching pattern (the ‘‘#’’
case) or the longest matching pattern (the ‘‘##’’ case) deleted.
If parameter is @ or *, the pattern removal operation is applied
to each positional parameter in turn, and the expansion is the
resultant list. If parameter is an array variable subscripted
with @ or *, the pattern removal operation is applied to each
member of the array in turn, and the expansion is the resultant
list.
似乎无法直接访问*部分,所以感谢您向我展示了使用变量也是可能的。