簡體   English   中英

對於半命令,我需要一些幫助才能完成,這是否可以在此命令中 cd 進入 output 中打印的目錄

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM