我正在尝试在 ubuntu 16.04 LTS 上使用 pkgsrc 。
安装很容易。
$ cvs -q -z3 -d [email protected]:/cvsroot checkout -P pkgsrc
$ ./bootstrap --unprivileged
然后我从源安装了解压包。看起来也很成功。
$ cd pkgsrc/archivers/unzip/
$ bmake
$ bmake install
$ which unzip
/home/xxxx/pkg/bin/unzip
然而执行的时候并没有起作用。
$ cd ~
$ ls
aaa.zip
$unzip aaa.zip
UnZip 6.00 of 20 April 2009, by Info-ZIP. Maintained by C. Spieler. Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.
Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
Default action is to extract files in list, except those in xlist, to exdir;
file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage).
-p extract files to pipe, no messages -l list files (short format)
-f freshen existing files, create none -t test compressed archive data
-u update files, create if necessary -z display archive comment only
-v list verbosely/show version info -T timestamp archive to latest
-x exclude files that follow (in xlist) -d extract files into exdir
modifiers:
-n never overwrite existing files -q quiet mode (-qq => quieter)
-o overwrite files WITHOUT prompting -a auto-convert any text files
-j junk paths (do not make directories) -aa treat ALL files as text
-C match filenames case-insensitively -L make (some) names lowercase
-X restore UID/GID info -V retain VMS version numbers
-K keep setuid/setgid/tacky permissions -M pipe through "more" pager
See "unzip -hh" or unzip.txt for more help. Examples:
unzip data1 -x joe => extract all files except joe from zipfile data1.zip
unzip -p foo | more => send contents of foo.zip via pipe into program more
unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
$ echo $?
10
$ ls
aaa.zip
错误代码是10,这意味着在命令行上指定了无效选项。为什么?我没想到我添加了任何选项。我很困惑。
于是我删除了pkgsrc的unzip来对比ubuntu的unzip,结果成功了。
$ pkg_delete unzip
$ which unzip
/usr/bin/unzip
$ /usr/bin/unzip aaa.zip
Archive: aaa.zip
extracting: aaa.txt
$ls
aaa.txt aaa.zip
pkgsrc 的解压缩已损坏?或者我是否忽略了一些我必须做的设置?
更新(2017-2-19 14:30):我正在阅读 pkgsrc 的源代码(pkgsrc/archivers/unzip)。它是在 后生成的bmake
。到目前为止,我对 unzip.c 进行了部分更改,如下所示:
-- unzip.c --
int MAIN(argc, argv)
int argc;
char *argv[];
{
int r;
CONSTRUCTGLOBALS();
/* for debug ----> */
int hoge;
printf("argc %d\n", argc);
for(hoge = 0; hoge < argc; hoge++){
printf("argv[%d] %s\n", hoge, argv[hoge]);
}
/* for debug <---- */
r = unzip(__G__ argc, argv);
DESTROYGLOBALS();
RETURN(r);
}
....
....
int unzip(__G__ argc, argv)
__GDEF
int argc;
char *argv[];
{
....
....
#endif /* !NO_ZIPINFO */
/* for debug ----> */
printf("argc: %d\n", argc);
printf("&argc: %d\n", &argc);
int hoge = 0;
for(hoge = 0; hoge < argc; hoge++){
printf("argv[%d]: %s\n", hoge, argv[hoge]);
}
/* for debug <---- */
error = uz_opts(__G__ &argc, &argv);
}
int uz_opts(__G__ pargc, pargv)
__GDEF
int *pargc;
char ***pargv;
{
...
...
while (++argv, (--argc > 0 && *argv != NULL && **argv == '-')) {
s = *argv + 1;
while ((c = *s++) != 0) { /* "!= 0": prevent Turbo C warning */
/* for debug ----> */
printf("c: %c\n",c);
/* for debug <---- */
#ifdef CMS_MVS
switch (tolower(c))
#else
switch (c)
#endif
{
case ('-'):
++negative;
break;
...
...
default:
printf("SET ERROR\n"); /* for debug */
error = TRUE;
break;
}
...
...
#endif /* !SFX */
return USAGE(error);
...
...
}
#else /* !SFX */
# ifdef VMS
# define QUOT '\"'
# define QUOTS "\""
# else
# define QUOT ' '
# define QUOTS ""
# endif
int usage(__G__ error) /* return PK-type error code */
__GDEF
int error;
{
if (error){
/* for debug ----> */
puts("PK_PARAM: L");
/* for debug <---- */
return PK_PARAM;
} else {
...
}
}
通过这个更改,我理解了 argc 和 argv 之前uz_opts()
在unzip()
.并且in 语句-O CP932
中不存在内部添加的选项,导致退出代码为 10。swich
uz_opts()
$ unzip aaa.zip
argc 2
argv[0] unzip
argv[1] /home/xxxx/aaa.zip
argc: 4
&argc: -740106452
argv[0]: unzip
argv[1]: -O
argv[2]: CP932
argv[3]: /home/xxxx/aaa.zip
c: O
SET ERROR
UnZip 6.00 of 20 April 2009, by Info-ZIP. Maintained by C. Spieler. Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.
Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
Default action is to extract files in list, except those in xlist, to exdir;
file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage).
-p extract files to pipe, no messages -l list files (short format)
-f freshen existing files, create none -t test compressed archive data
-u update files, create if necessary -z display archive comment only
-v list verbosely/show version info -T timestamp archive to latest
-x exclude files that follow (in xlist) -d extract files into exdir
modifiers:
-n never overwrite existing files -q quiet mode (-qq => quieter)
-o overwrite files WITHOUT prompting -a auto-convert any text files
-j junk paths (do not make directories) -aa treat ALL files as text
-C match filenames case-insensitively -L make (some) names lowercase
-X restore UID/GID info -V retain VMS version numbers
-K keep setuid/setgid/tacky permissions -M pipe through "more" pager
See "unzip -hh" or unzip.txt for more help. Examples:
unzip data1 -x joe => extract all files except joe from zipfile data1.zip
unzip -p foo | more => send contents of foo.zip via pipe into program more
unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
PK_PARAM: L
然后我检查了环境变量,它就在那里......
$env
...
...
UNZIP=-O CP932
这是什么?我无法在我的.profile
和.bashrc.
答案1
我明白了这个问题的原因。这是一个环境变量。
$ env | sort
...
...
UNZIP=-O CP932
根据这一页(抱歉,它是用日语编写的),UNZIP
需要此变量来提取在 Windows 中创建的包含多字节字符(例如日语字符)的 zip 存档。我猜想这个变量是由 Ubuntu 的日文版解压包导入的。
因此,我必须禁用 UNZIP 变量,如下所示:
$ UNZIP='' unzip aaa.zip
Archive: aaa.zip
extracting: aaa.txt
$ ls
aaa.zip aaa.txt