gzip - 任何人都可以解释 cmd.exe 和 gzip 的这种奇怪的变量扩展行为吗?

标签 gzip cmd

我在使用 gzip.exe 时遇到以下问题,无论是来自 UnxUtils 还是来自 GnuWin32:

set gzip=.\util\gzip.exe
%gzip% test.txt
%gzip% test2.txt

第二个 gzip 命令将发出如下警告:

gzip: .\util\gzip.exe.gz already exists; do you wish to overwrite (y or n)?

所以:gzip 尝试压缩自身(并且它仍然压缩 test2.txt)。 就像命令行是: .\util.gzip.exe .\util.gzip.exe test2.txt.

但是,当在我的批处理中我的变量未命名为 gzip 时,它可以正常工作。

set gzip_prg=.\util\gzip.exe
%gzip_prg% test.txt
%gzip_prg% test2.txt

我完全不明白变量名的选择如何影响扩展后运行的命令行。

简而言之,当我更改变量名称时,我的批处理脚本的行为方式不同!

有人能解释一下这种现象吗?

最佳答案

我自己找到了答案。

gzip.exe reads the GZIP environment variable这有助于设置选项。

这里,gzip 读取环境变量并认为它必须压缩自身。

关于gzip - 任何人都可以解释 cmd.exe 和 gzip 的这种奇怪的变量扩展行为吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6249079/

相关文章:

windows - Emacs - 尝试打开信息文件时未找到 "Uncompression program ' gzip“

c++ - 从函数返回时错误 boost filtering_ostream

perl - 启动 nikto 扫描仪。 'No web server found'

windows - Windows 中的 FTP 命令挂起并显示 "150 Opening data channel for file download from server of ..."

mysqldump + gzip 制作 0 字节 gz 文件

Java GZip 在压缩文件和再次解压缩时会产生细微差别

php - 如何解码/膨胀分块的 gzip 字符串?

windows - 替换 findstr 命令输出中的字符串

c# - 使用 BackgroundWorker.Backgroundworker 显示命令提示符输出

字符编码 C 和瑞典语 åöä