help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature request: built-in variable for the whole previous command input


From: Ante Bilandzic
Subject: feature request: built-in variable for the whole previous command input
Date: Fri, 9 Jul 2021 10:36:26 +0200

Hello,

There is a built-in variable $_ which retrieves the last word (argument) of
the previous command input. Would it be possible to add in the same fashion
a new built-in variable that retrieves the whole previous command input
(command + all its arguments)?

I was trying with 'echo !!' or 'fc -ln -1' but they seem to work only in an
interactive session in the terminal, and not when sourced in the script.

Use case: We can then write very compactly and elegantly in the scripts
code snippets like this:

some-command-input || { echo $requested-new-built-in-variable; return 1; }

At Stackoverflow I was pointed to
https://stackoverflow.com/questions/6109225/echoing-the-last-command-run-in-bash
. But none of these suggestions and workarounds are really up to my taste
(with them scripts get longer and not shorter, as intended with my feature
request).

Thanks!

Cheers,
Ante


reply via email to

[Prev in Thread] Current Thread [Next in Thread]