【问题标题】:Compiling files in a directory into their own zip folder using a makefile script使用 makefile 脚本将目录中的文件编译到自己的 zip 文件夹中
【发布时间】:2019-09-18 12:27:15
【问题描述】:

我目前正在上课,我们通过在线工具提交作业。但是,它要求提交由单独的压缩文件组成,以便正确编译它们。当我有时会提交多个文件时,这很耗时。我正在尝试编写一个制作文件脚本来制作同一文件夹中所有文件的压缩副本。然后,我想将这些压缩文件移动到我之后创建的名为 zippedFiles 的子目录中。这就是我到目前为止所拥有的。当我直接在终端中运行 for 循环行时它可以工作,但是当我运行 make zip 时出现以下错误我收到以下错误:zip 错误:无事可做! (.zip) 我是学习 bash 和制作文件的新手,无法自行研究解决方案。

zip:
    rm -f ./*zip    #remove any extra zip copies.
    rm -rf zippedFiles #delete old zippedFiles
    for i in *; do zip $i.zip $i; done #zip each file ***not working
    mkdir zippedFiles       #remake new zippedFiles directory

【问题讨论】:

    标签: bash makefile terminal


    【解决方案1】:

    在 makefile 中,您必须使用两次 $ 来引用来自 for 循环的变量。

    for i in *; do zip $$i.zip $$i; done

    【讨论】:

    • 要对此进行扩展,make 将看到 $i,假设它是一个 make 变量,并在将字符串 for i in *; do zip .zip ; done 传递给 shell 之前将其扩展(为空白,因为它没有设置)。如果你使用$$,make 将其扩展为$,然后再传递给shell。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多