【问题标题】:Problems with script that unzips multiple zipped tar files then untars the same files in C shell解压缩多个压缩 tar 文件然后在 C shell 中解压缩相同文件的脚本问题
【发布时间】:2020-04-02 01:32:58
【问题描述】:

我一直在尝试编写一个脚本,该脚本将在一个目录中搜索多个压缩的 tar 文件,解压缩它们,然后解压缩它们。但是我的问题是,每次我运行脚本时,它都会执行第一个 if then 语句,但不会执行第二个。我已经在单独的脚本中运行了它们两个语句,它们都独立工作,但是在同一个脚本中运行时不是。我需要将它们组合在 if then elseif 语句中吗?这是我目前所拥有的,感谢任何帮助。

#!/bin/csh
set x = (`find /Documents/*.gz -print`)
set v = (`find /Documents/*.tar -print`)

if ("$x" != "") 
then 
gunzip *
else
echo "No zip files found."
endif

if ("$v" != "")  then
foreach i ( $v )
tar -xvf $i
end
else
echo "No tar files found."
endif

【问题讨论】:

    标签: if-statement foreach unzip csh


    【解决方案1】:

    你可以用find做同样的事情;你真的不需要循环:

    find /Documents/*.gz -exec gunzip {} \;
    find /Documents/*.tar -exec tar xvf {} \;
    

    -exec 将对其找到的每个文件运行命令,{} 被文件名替换,\; 终止命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 2013-03-09
      • 1970-01-01
      • 2010-09-05
      • 1970-01-01
      相关资源
      最近更新 更多