[英]for half command I need some help to complete, is this possible in this command to cd into the directory thats printed in output
當我做ls | grep -e *-folder1
ls | grep -e *-folder1
它打印my-folder1
即當前目錄中命令中匹配的文件夾的名稱。 有沒有辦法可以在這個目錄中添加類似 cd 的東西。 這更多的是嘗試學習 bash 或 linux 上的命令。 因為它是關於做我想要完成的事情。
你可以做
ls | grep -- -folder1 | while read -r dir
do
cd "$dir"
# do things in $dir
done
# do things in the original directory
但不推薦解析ls
的 output 。 您可以改為使用通配符:
for dir in *-efolder*
do
cd "$dir"
# do things in $dir
cd .. # need to back out again
done
# do things in the original directory
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.