Jos*_*vin 5 bash zsh file-search shell-script
我想在 shell 脚本中“向上”搜索文件,例如检查 $PWD,然后 $PWD/..,然后 $PWD/../.. 等,直到找到根目录。在我自己动手之前,是否有一些内置的 bash/zsh/find 魔法可以为我做到这一点?
好吧,我不知道如何在 zsh 中执行此操作,因为我使用 bash:但我尝试了这个衬垫
START=$PWD; while [ $PWD != "/" ]; \
do ls|grep file && echo $PWD ;cd ..; done ; cd $START
Run Code Online (Sandbox Code Playgroud)
如果您想在找到可以使用的东西时停止:
START=$PWD; while [ $PWD != "/" ]; do \
ls|grep file && echo $PWD && cd $START && break;cd ..; done
Run Code Online (Sandbox Code Playgroud)
据我所知,没有这样的工具可以做到这一点。