什么机制允许 linux less 命令读取加密的 gpg 文件

What mechanism allows linux less command to read an encrypted gpg file

使用对称加密对文件进行加密后,我决定通过键入以下内容来确认输出已加密:

gpg -c --force-mdc --s2k-mode 3 --s2k-count 65011712 --output doc.gpg doc.txt

less doc.gpg

令我惊讶的是,less 命令自动解密了 doc.gpg 的内容并将它们显示给我,而不是显示文件的原始加密内容。这只发生在 "less" 命令中,而不是 "cat" 命令中。如果 "less doc.gpg" 在另一台机器上完成,将出现一个命令行弹出对话框,要求输入密码。

任何人都可以解释一下是什么机制导致 gpg 自动与 "less" 命令集成,以及这种自动集成将与哪些其他命令一起发生?谢谢!

从这里开始:

$ man less

稍作阅读,发现:

INPUT PREPROCESSOR

You may define an "input preprocessor" for less. Before less opens a file, it first gives your input preprocessor a chance to modify the way the contents of the file are displayed...

...To set up an input preprocessor, set the LESSOPEN environment variable to a command line which will invoke your input preprocessor. This command line should include one occurrence of the string "%s", which will be replaced by the filename when the input preprocessor command is invoked.