You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用zip命令-R@选项搭配文件列表报错的技术求助

解决zip按混合规则打包文件的问题

核心问题原因

你用的zip -R@参数组合不兼容:-R是递归匹配模式,需要指定匹配规则;-@是从标准输入读取具体文件路径,两者逻辑冲突,所以才会报错zip error: Invalid command arguments (nothing to select from)。

实用解决方案

方案1:用shell脚本解析规则(推荐)

创建一个build-zip.sh脚本,用来解析你的ziplist.txt,自动处理单个文件和带通配符的目录:

#!/bin/bash
# 读取规则文件,逐行解析
while IFS= read -r line; do
  # 跳过空行
  [[ -z "$line" ]] && continue
  # 解析通配符,输出所有匹配的文件路径
  eval "echo $line"
done < ziplist.txt | zip application.zip -@

在Bitbucket Pipelines里执行以下步骤:

  • 给脚本加执行权限:chmod +x build-zip.sh
  • 运行脚本:./build-zip.sh

方案2:直接用单行命令(无需脚本)

如果不想额外加脚本,用以下命令也能实现:

cat ziplist.txt | while IFS= read -r path; do
  if [[ "$path" == *"*"* ]]; then
    # 处理带通配符的路径,用find精准匹配文件
    find . -path "./$path" -type f
  else
    # 单个文件直接输出路径
    echo "$path"
  fi
done | zip application.zip -@

验证结果

执行完打包命令后,用unzip -l application.zip查看压缩包内容,会得到你期望的文件列表:

file1.txt
folder1/file2.js
folder1/folder2/file5.jpg
folder1/folder3/file6.tsx
folder1/folder3/file7.mp3

内容的提问来源于stack exchange,提问作者Ben Steenson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 08:15:32