我有一個循環這樣一個bash:由*訪問*在bash for循環
1
A
回答
2
也許這樣匹配的文本替換
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
0
for i in /long/path/filename*;
do echo ${i%filename*}/other/path/c01/${i#/long/path/filename};
done
從man bash
:
${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.
+1
不應該'/%{i'是'/ $ {i'? –
+0
@阿德里安:謝謝。錯字+1。 –
相關問題
- 1. bash的for循環問題
- 2. Bash,for循環問題
- 3. 訪問-VBA for循環
- 4. 訪問使用for循環
- 5. 訪問指針for循環
- 6. for循環訪問列表
- 7. 在bash中循環訪問數組
- 8. 問題與表達For循環 - Bash
- 9. Bash ssh for循環 - env變量問題
- 10. 如何訪問變量在for循環
- 11. JAVA-如何從for循環訪問FOR循環中的變量
- 12. bash腳本For循環*
- 13. Bash for循環語法
- 14. bash的for循環不循環(AWK時,bash,LINUX)
- 15. 在bash shell上循環「for..do」
- 16. 在BASH for循環這裏文檔
- 17. 在bash「for」循環中排序
- 18. 在bash for循環中分離進程
- 19. 使用for循環訪問jQuery ID
- 20. 訪問可變外部for循環
- 21. 訪問數組索引OutSide For循環
- 22. 通過for循環縮略圖訪問。
- 23. 使用for循環訪問imageviews數組
- 24. 訪問For循環隱藏對象
- 25. PHP的For循環不被訪問
- 26. 訪問for循環中創建的spritenodes?
- 27. System.Threading.Tasks for for循環問題
- 28. 問題for循環在smalltalk
- 29. 疑問,在for循環
- 30. for循環問題
看起來好像沒有辦法直接訪問*部分,所以感謝您向我展示使用變量也是可能的。 –