使用unix shell脚本循环浏览zip文件中的文件夹

使用unix shell脚本循环浏览zip文件中的文件夹,unix,Unix,我的zip文件中有我的文件夹。解压缩我的zip文件后,我想在zip中迭代一个可用文件夹的循环 内部循环条件如下所示: 如果我的文件夹有索引文件(这是一个包含一些数据的文件),那么我只想运行一些进程(我知道这个进程是什么…)。否则,我们可以忽略该文件夹 然后循环将继续与其他文件夹,如果有什么 谢谢你的帮助。像这样的事 (注意:我假设$destdir将只包含zipfile及其提取!) 注意:我在/*/上迭代,而不是*/,因为dirname可能包含一个leding-,因此使cd-something无法

我的zip文件中有我的文件夹。解压缩我的zip文件后,我想在zip中迭代一个可用文件夹的循环

内部循环条件如下所示:

如果我的文件夹有索引文件(这是一个包含一些数据的文件),那么我只想运行一些进程(我知道这个进程是什么…)。否则,我们可以忽略该文件夹

然后循环将继续与其他文件夹,如果有什么

谢谢你的帮助。

像这样的事

(注意:我假设$destdir将只包含zipfile及其提取!)


注意:我在
/*/
上迭代,而不是
*/
,因为dirname可能包含一个leding
-
,因此使
cd-something
无法工作(它会说它无法识别某些选项!)!这将随着
/
cd.而消失。/-有些东西会起作用的

你试过什么?您希望运行的流程是什么?我会将文件解压缩到一个位置,然后在该位置内,使用
find
-execdir
来运行该进程(当然,这取决于它是什么)。不需要循环。嗨。/*/不工作。。它给出了以下错误:bash:./test1/:是i在$中的一个目录(find.-type d)尝试这个for循环。@user3436748:最好使用我的方法(
for i in./*/;do…
),而不是
查找
ls
(请参见上面的答案1和3!),我很惊讶:你确定你复制/粘贴了我的程序吗?因为我不知道它会在哪里显示此错误消息。。。
zipfile="/path/to/the/zipfile.zip"
destdir="/path/to/where/you/want/to/unzip"
indexfile="index.txt" #name of the index files
mkdir -p "$destdir" 2>/dev/null  #make "sure" it exists.. but ignore errors in case it already exists

cd "$destdir" || { echo "Can not go into destdir=$destdir" ; Exit 1 ; }
#at that point, we are inside $destdir : we can start to work:
unzip "$zipfile"
for i in ./*/ ; do  # you could change ./*/ to ./*/*/ if the zip contains a master directory too
   cd "$i" && {  #the && is important: you want to be sure you could enter that subdir!
      if [ -e ./"$indexfile" ]; then
          dosomething  # you can define the function dosomething and use it here.. 
                       # or just place commands here
      fi
      cd - #we can safely this works, as we started there...
   }
done