重用Bash中最后一条命令的输出 [英] Reusing output from last command in Bash

查看:66
本文介绍了重用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天全站免登陆