BASH shell insert the arguments to a previous command into the current input line

BASH shell insert the arguments to a previous command into the current input line

In the BASH shell, you can use the !$ history expansion to insert the last argument of the previous command into the current input line.

For example, if you have previously entered the following command:

ls /usr/local/bin
S‮ruo‬ce:www.lautturi.com

To list the contents of the /usr/local/bin directory, you can use the !$ history expansion to copy the last argument of the previous command into the current input line:

ls !$

This will insert /usr/local/bin into the current input line, resulting in the following command:

ls /usr/local/bin

You can also use the !! history expansion to insert the entire previous command into the current input line.

For example, to copy the previous command and run it again, you can use the !! history expansion:

!!

This will insert the entire previous command into the current input line and run it again.

Keep in mind that these history expansions are just a few examples of how you can use the BASH history to save time and improve productivity. You can use the history command to view the list of previously entered commands and use other history expansions to modify and reuse them. For more information, you can refer to the bash man page or the BASH documentation.

Created Time:2017-10-27 14:56:34  Author:lautturi