gpt4 book ai didi

linux - 当路径包含空格时,使用 bash 在 Linux 中解压缩文件会导致错误

转载 作者:太空狗 更新时间:2023-10-29 12:04:37 26 4
gpt4 key购买 nike

文件路径如下:路径/路径/路径/文件名 2.3.pdf.zip

我做错了什么:

# unzip files back to normal
# and remove zip files
for f in `find "$1" -type f -iname "*.zip"`; do
dir=`dirname "$f"`
unzip -o "$f" -d "$dir"
rm -f "$f"
done

错误信息:解压缩:无法找到或打开文件、file.zip 或 file.ZIP

使用 UnZip 5.52红帽企业 Linux 服务器版本 5.10 (Tikanga)

最佳答案

我认为您的循环正在根据空格拆分 find 的输出。你可能想做一些事情来一次读一行,就像这样

find "$1" -type f -iname "*.zip" | while read f
do
dir=`dirname "$f"`
unzip -o "$f" -d "$dir"
rm -f "$f"
done

或者,您可以设置 IFS:

IFS='\n'
for f in `find "$1" -type f -iname "*.zip"`; do
dir=`dirname "$f"`
unzip -o "$f" -d "$dir"
rm -f "$f"
done

关于linux - 当路径包含空格时,使用 bash 在 Linux 中解压缩文件会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19435136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com