Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash for循环中的Access*_Bash - Fatal编程技术网

bash for循环中的Access*

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},可能是

我有这样一个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

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.

似乎无法直接访问*部分,所以感谢您向我展示了使用变量也是可能的。