gpt4 book ai didi

bash - 将最后一个命令存储在 Bash 中的变量中

转载 作者:IT王子 更新时间:2023-10-29 00:57:26 26 4
gpt4 key购买 nike

我想将最近的命令存储在一个变量中。我尝试了 !!:p 历史扩展,它确实为我提供了最后一条命令,但我无法将其存储在变量中。

$ last=`!!:p`
last=`ls`
$ echo $last

$

有什么帮助吗?

最佳答案

fc 命令可用于检索之前的命令。

some_var=$(fc -nl -1)

关于bash - 将最后一个命令存储在 Bash 中的变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40715729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com