小编Eer*_*nen的帖子

仅 tar 列表文件

有趣的事实:如果您使用存档管理器并提取 .tar.gz 以便您取消选中“保持目录结构”,您将获得一个tarbomb

tar -ztf列出 tar 文件中的所有文件和目录。有没有办法在没有目录结构的情况下列出 tar 文件中的所有文件?

tar

19
推荐指数
2
解决办法
5万
查看次数

处理可能带有空格的文件名列表的 POSIX 兼容方式

我已经看到 Bash 脚本指南建议使用数组来处理包含空格的文件名。然而,DashAsBinSh表明数组不可移植,所以我正在寻找一种符合 POSIX 的方式来处理可能包含空格的文件名列表。

我正在寻找修改下面的示例脚本,以便它 echo

foo/target/a.jar
foo/target/b.jar
bar/target/lol whitespace.jar
Run Code Online (Sandbox Code Playgroud)

这是脚本

#!/usr/bin/env sh

INPUT="foo/target/a.jar
foo/target/b.jar
bar/target/b.jar
bar/target/lol whitespace.jar"
# this would be produced by a 'ls' command
# We can execute the ls within the script, if it helps

dostuffwith() { echo $1; };

F_LOCATIONS=$INPUT
ALL_FILES=$(for f in $F_LOCATIONS; do echo `basename $f`; done)
ALL_FILES=$(echo "$ALL_FILES" | sort | uniq)

for f in $ALL_FILES
do
    fpath=$(echo "$F_LOCATIONS" | grep -m1 $f)
    dostuffwith $fpath
done
Run Code Online (Sandbox Code Playgroud)

shell-script filenames posix quoting whitespace

16
推荐指数
2
解决办法
5483
查看次数

标签 统计

filenames ×1

posix ×1

quoting ×1

shell-script ×1

tar ×1

whitespace ×1