【发布时间】:2017-03-04 08:58:34
【问题描述】:
我正在尝试使用“SSH EXEC”类型构建步骤编写一个脚本来重新启动我在 teamcity 中的服务器。
脚本要做的一件事是解压缩我在上一步中上传的 zip 文件,但文件名中的版本总是会改变,所以我尝试使用嵌套命令查找 zip 的名称.
unzip `ls | grep zip`
当我 ssh 到我的服务器并在终端中执行此操作时,这对我有用,但当 teamcity 尝试执行此操作时它不起作用。我在构建日志中收到以下消息
[19:36:55][Step 3/3] UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.
[19:36:55][Step 3/3]
[19:36:55][Step 3/3] Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
[19:36:55][Step 3/3] Default action is to extract files in list, except those in xlist, to exdir;
[19:36:55][Step 3/3] file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage).
[19:36:55][Step 3/3]
[19:36:55][Step 3/3] -p extract files to pipe, no messages -l list files (short format)
[19:36:55][Step 3/3] -f freshen existing files, create none -t test compressed archive data
[19:36:55][Step 3/3] -u update files, create if necessary -z display archive comment only
[19:36:55][Step 3/3] -v list verbosely/show version info -T timestamp archive to latest
[19:36:55][Step 3/3] -x exclude files that follow (in xlist) -d extract files into exdir
[19:36:55][Step 3/3] modifiers:
[19:36:55][Step 3/3] -n never overwrite existing files -q quiet mode (-qq => quieter)
[19:36:55][Step 3/3] -o overwrite files WITHOUT prompting -a auto-convert any text files
[19:36:55][Step 3/3] -j junk paths (do not make directories) -aa treat ALL files as text
[19:36:55][Step 3/3] -U use escapes for all non-ASCII Unicode -UU ignore any Unicode fields
[19:36:55][Step 3/3] -C match filenames case-insensitively -L make (some) names lowercase
[19:36:55][Step 3/3] -X restore UID/GID info -V retain VMS version numbers
[19:36:55][Step 3/3] -K keep setuid/setgid/tacky permissions -M pipe through "more" pager
[19:36:55][Step 3/3] -O CHARSET specify a character encoding for DOS, Windows and OS/2 archives
[19:36:55][Step 3/3] -I CHARSET specify a character encoding for UNIX and other archives
[19:36:55][Step 3/3]
[19:36:55][Step 3/3] See "unzip -hh" or unzip.txt for more help. Examples:
[19:36:55][Step 3/3] unzip data1 -x joe => extract all files except joe from zipfile data1.zip
[19:36:55][Step 3/3] unzip -p foo | more => send contents of foo.zip via pipe into program more
[19:36:55][Step 3/3] unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
[19:36:56][Step 3/3] SSH exit-code [0]
【问题讨论】:
-
为什么不直接
unzip *.zip? -
我也在使用这种嵌套命令样式来执行其他命令。所以我仍然想知道为什么嵌套命令不起作用。谢谢你的信息!我不知道 unzip 可以使用正则表达式
-
通配符由shell扩展,它们自动适用于每个命令。
-
这不是正则表达式,而是通配符 AKA glob。