小编Nat*_*ace的帖子

为什么某些程序(如 readlink)不能从管道中获取输入?

我在我$PATH想要编辑的文件中有一个指向脚本的符号链接。我忘记了文件路径,所以我尝试执行以下操作:

$ which my_script_link | readlink
Run Code Online (Sandbox Code Playgroud)

我希望输出文件路径,但它输出

> readlink: missing operand
> Try 'readlink --help' for more information
Run Code Online (Sandbox Code Playgroud)

我之前在其他情况下也看到过类似的行为(比如尝试将文件列表通过管道传输到 vim 中进行编辑)。我知道有一些解决方法,比如 subshel​​l readlink $(which my_script_link),但我想了解为什么管道在这种情况下不能像我认为的那样工作。

谢谢!

pipe

7
推荐指数
2
解决办法
1万
查看次数

gpg2 解密超时/没有密钥

我在用 gpg2 解密文件时遇到问题。我最初使用 gpg 1.4 版加密文件。我现在使用的机器有 gpg (1.4) 和 gpg2。用 gpg 解密工作得很好,但是当我用 gpg2 执行相同的命令时,它超时了:

$ echo "This is a test" > test.txt
$ gpg -r MyOwnId --encrypt test.txt
  (creates test.txt.gpg)
$ gpg --decrypt test.txt.gpg
  (provide passphrase for MyOwnId)
  -> This is a test
$ gpg2 --decrypt test.txt.gpg
  (after a long timeout)
  -> gpg: encrypted with 2048-bit RSA key, ID #######, created YYYY-MM-DD "MyOwnId"
     gpg: public key decryption failed: Timeout
     gpg: decryption failed: No secret key
Run Code Online (Sandbox Code Playgroud)

这是怎么回事?它说“没有密钥”,但运行 gpg2 --list-secret-keys 显示:

/home/me/.gnupg/pubring.kbx …
Run Code Online (Sandbox Code Playgroud)

gnome gnome-keyring gpg

7
推荐指数
1
解决办法
3290
查看次数

将同一行的两个字段放在一起

我有一种情况,我有几行,我需要每行都有两个不同的字段。具体来说,我在参考书目中有一个参考列表,我想获得姓氏和年份。

样本输入:

Aloise-Young, P.A. (1993). The development of self-presentation.  Self-promotion in 6- to 10-year-old children. Social Cognition, 11, 201-222.
Banerjee, R. (2002). Children's understanding of self-presentational behavior: Links with mental-state reasoning and the attribution of embarrassment. Merril-Palmer Quarterly, 48, 378-404.
Bennett, M., & Wellman, H. (1989). The role of second-order belief-understanding and social context in children's self-attribution of social emotions. Social Development, 9, 126-130.
Run Code Online (Sandbox Code Playgroud)

期望的输出:

Aloise-Young 1993
Banerjee 2002
Bennett 1989
Run Code Online (Sandbox Code Playgroud)

我可以得到姓氏 cat file | cut -d, -f1

我可以得到岁月 cat …

bash text-processing

4
推荐指数
1
解决办法
1420
查看次数

标签 统计

bash ×1

gnome ×1

gnome-keyring ×1

gpg ×1

pipe ×1

text-processing ×1