如何从终端读取隐藏的输入并将其管道到另一个命令

发布于 2025-01-27 21:55:20 字数 732 浏览 2 评论 0原文

我希望能够在终端中牢固地键入文本,然后将其置于另一个命令中:

  • 在您键入键入时,在终端历史记录中不记录
  • 下来,它
  • 不会在任何文件或环境变量中记录
  • 在最短的时间内记忆中,

理想情况下:

  • 使用 : Linux上的常用工具
  • 易于使用,因为echo
  • 不必创建任何脚本/文件,
  • 可以将

非安全输入的示例输送到其他命令示例

echo "secret" | wc -c

任何我想要的

read -s | wc -c

:基本上就像如何将密码输入到sudo和类似。

我的用例

echo "secret" | gpg --encrypt --armor -r 1234567890ABCDEF | xclip

我正在寻找一种在上面点上提到的限制的方法。知道我正在寻找的不存在也是我会接受和标记的答案。

我从接受的答案中创建了别名

alias secnote="{ read -s; printf %s $REPLY; } | gpg --encrypt --armor -r 123467890ABCDEF | pbcopy"

I would like to be able securely type text in terminal and pipe it to another command to:

  • Not be recorded in terminal history
  • Be hidden as you type it
  • Not be recorded in any file or environmental variable
  • Be in memory for shortest possible time

Ideally:

  • Using commonly installed tools on linux
  • Easy to use as echo
  • Not having to create any scripts/files
  • Can be piped to other commands

Example of non secure input

echo "secret" | wc -c

Almost what I want:

read -s | wc -c

Basically the same way how you input password to sudo and similar.

My use case

echo "secret" | gpg --encrypt --armor -r 1234567890ABCDEF | xclip

I am looking for a way with restrictions I mentioned in points above. Knowing that what I am looking for doesn't exist is also an answer I will accept and mark.

I created alias from accepted answer

alias secnote="{ read -s; printf %s $REPLY; } | gpg --encrypt --armor -r 123467890ABCDEF | pbcopy"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦晓ヶ微光ヅ倾城 2025-02-03 21:55:20

这是您想实现的目标吗?

$ read -s       # I type `secret`
$ echo $REPLY
secret
$ printf %s $REPLY | wc -c
6
$ unset REPLY
$ echo $REPLY
# empty now

或者您想要这样的单线:

{ read -s -p "Input a secret: "; printf %s $REPLY; } | wc -c

如果定义一个别名:

alias readp='{ read -s -p "Input a secret: "; printf %s $REPLY; }'

那么您可以做readp | WC -C

Is this what you wanted to achieve ?

$ read -s       # I type `secret`
$ echo $REPLY
secret
$ printf %s $REPLY | wc -c
6
$ unset REPLY
$ echo $REPLY
# empty now

Or you want one-liner like this :

{ read -s -p "Input a secret: "; printf %s $REPLY; } | wc -c

If you define an alias :

alias readp='{ read -s -p "Input a secret: "; printf %s $REPLY; }'

then you can do readp | wc -c

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文