在 Bash 中重用上一个命令的输出 [英] Reusing output from last command in Bash

查看:26
本文介绍了在 Bash 中重用上一个命令的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bash 命令的输出是否存储在任何寄存器中?例如.类似于 $? 捕获输出而不是退出状态.

Is the output of a Bash command stored in any register? E.g. something similar to $? capturing the output instead of the exit status.

我可以将输出分配给一个变量:

I could assign the output to a variable with:

output=$(command)

但这需要更多的打字...

but that's more typing...

推荐答案

您可以使用 $(!!)重新计算(不是重复使用)最后一个命令的输出.

You can use $(!!) to recompute (not re-use) the output of the last command.

!! 自己执行最后一个命令.

The !! on its own executes the last command.

$ echo pierre
pierre
$ echo my name is $(!!)
echo my name is $(echo pierre)
my name is pierre

这篇关于在 Bash 中重用上一个命令的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆