use*_*271 5 updates package-management command-line apt
我有一个 zsh 函数来更新我的系统(.deb
包、pip
包、texlive 包,...)。
它看起来像这样:
up() {
emulate -LR zsh
[[ -d "${HOME}/log" ]] || mkdir "${HOME}/log"
LOGFILE="${HOME}/log/update_system.log"
__update_system 2>&1 | tee -a "${LOGFILE}"
}
Run Code Online (Sandbox Code Playgroud)
最后一行调用该__update_system
函数并将其输出通过管道传送到tee
,后者应在终端上显示输出,并将其附加到文件中,以便我以后在出现问题时可以查看它。
执行的命令之一__update_system
是:
$ apt-file update
Run Code Online (Sandbox Code Playgroud)
它似乎被执行了,但它的输出没有记录在文件中。记录所有其他命令(包括aptitude update
)。
我试图通过在 shell 中执行这个命令来理解:
$ apt-file update >/tmp/log
Run Code Online (Sandbox Code Playgroud)
同样,apt-file update
似乎已执行,但输出未记录为/tmp/log
空。
我想也许输出是在标准错误上发送的,所以我试过:
$ apt-file update >/tmp/log 2>&1
Run Code Online (Sandbox Code Playgroud)
但我得到了相同的结果,一个空文件。
我在 bash 中尝试过,它也给了我一个空文件。
以下是有关我的系统的一些详细信息:
$ uname -a
Linux ubuntu 4.4.0-135-generic #161-Ubuntu SMP Mon Aug 27 10:45:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
关于 zsh:
$ zsh --version
zsh 5.5.1-dev-0 (x86_64-pc-linux-gnu)
Run Code Online (Sandbox Code Playgroud)
关于 bash:
$ bash --version
GNU bash, version 4.4.0(1)-release (x86_64-unknown-linux-gnu)
Run Code Online (Sandbox Code Playgroud)
关于apt-file
:
$ aptitude show apt-file
Package: apt-file
State: installed
Automatically installed: no
Version: 2.5.5ubuntu1
Priority: optional
Section: universe/admin
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: all
Uncompressed Size: 92,2 k
Depends: perl, curl, libconfig-file-perl, libapt-pkg-perl, liblist-moreutils-perl, libregexp-assemble-perl,
libfile-temp-perl
Suggests: openssh-client, sudo
Description: search for files within Debian packages (command-line interface)
apt-file is a command line tool for searching files contained in packages for the APT packaging system. You can search
in which package a file is included or list the contents of a package without installing or fetching it.
Run Code Online (Sandbox Code Playgroud)
如何将输出重定向apt-file update
到文件中?
apt-file
是一个 perl 脚本。/dev/tty
和不写信stdout
(这个SO answer解释了这个区别)Soooo...这会将输出记录到 logfile.log
script -c "apt-file update" logfile.log
Run Code Online (Sandbox Code Playgroud)