zip命令不起作用 [英] zip command not working

查看:116
本文介绍了zip命令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Shell脚本命令压缩文件.我正在使用以下命令:

I am trying to zip a file using shell script command. I am using following command:

  zip ./test/step1.zip $FILES

其中$ FILES包含所有输入文件.但是我收到如下警告

where $FILES contain all the input files. But I am getting a warning as follows

    zip warning: name not matched: myfile.dat

还有另一件事,我观察到文件夹中文件列表中最后出现的文件具有以上警告,并且该文件未压缩.

and one more thing I observed that the file which is at last in the list of files in a folder has the above warning and that file is not getting zipped.

有人可以解释我为什么会这样吗?我是Shell脚本世界的新手.

Can anyone explain me why this is happening? I am new to shell script world.

推荐答案

zip警告:名称不匹配:myfile.dat

zip warning: name not matched: myfile.dat

这意味着文件 myfile.dat 不存在.

如果文件是指向不存在文件的符号链接,则会出现相同的错误.

You will get the same error if the file is a symlink pointing to a non-existent file.

正如您所说,无论 $ FILES 的最后一个文件是什么,它都不会与警告一起添加到zip文件中.因此,我认为您创建 $ FILES 的方式有问题.可能在最后一个文件名的末尾有换行符,回车符,空格,制表符或其他不可见字符,从而导致某些不存在的内容.尝试以下示例:

As you say, whatever is the last file at the of $FILES, it will not be added to the zip along with the warning. So I think something's wrong with the way you create $FILES. Chances are there is a newline, carriage return, space, tab, or other invisible character at the end of the last filename, resulting in something that doesn't exist. Try this for example:

for f in $FILES; do echo :$f:; done

我敢打赌最后一行将是错误的,例如:

I bet the last line will be incorrect, for example:

:myfile.dat :

...或类似的内容,而不是:myfile.dat:,最后一个:

...or something like that instead of :myfile.dat: with no characters before the last :

更新

如果您说脚本在运行 dos2unix 之后开始工作,则可以确认每个人已经怀疑的内容,即在 $ FILES末尾出现了回车符列表.

If you say the script started working after running dos2unix on it, that confirms what everybody suspected already, that somehow there was a carriage-return at the end of your $FILES list.

od -c 显示\ r回车符.尝试 echo $ FILES |od -c

od -c shows the \r carriage-return. Try echo $FILES | od -c

这篇关于zip命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆