简体   繁体   English

Bash 的 $_ 变量未扩展 [暂停]

[英]Bash's $_ variable not expanding [on hold]

The $_ variable, which should expand with the arguments of the last executed command in Bash, contains _lp_runtime_before . $_变量应该与 Bash 中最后执行的命令的 arguments 一起扩展,包含_lp_runtime_before No matter how many times I run a command, that would be the content it has.无论我运行多少次命令,这将是它的内容。 Why?为什么?

Actually, $_ expand to the last argument of the last command line, according to the man page of bash :实际上,根据bash的手册页, $_ 扩展为最后一个命令行的最后一个参数

[$_] expands to the last argument to the previous command, after expansion. [$_] 在展开后展开到前一个命令的最后一个参数。

If you want the whole arguments, use ::* :如果您想要整个 arguments,请使用::*

$ ls -a -l -h test
[blah blah]
$ last_command="!:*" > /dev/null

$ echo $last_command
-a -l -h test

I added a redirection of stdout to null device to prevent bash to print the expansion.我添加了stdout到 null 设备的重定向,以防止 bash 打印扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM