How to get last command argument value in follow up command in Linux ?

In this post we will look how to get the last command argument value in the current command.

For this, we will use a special bash bultin variable $_

Lets see few examples to understand this variable use.

Use of $_ to get last argument value

Example 1

### Lets echo hello and then echo it again using $_
[root@ngelinux ~]# echo "hello"; echo $_
hello
hello
[root@ngelinux ~]# 

Example 2

### Another example to print last argument value
[root@ngelinux ~]# id -a saket ; echo "$_ user details successfully processed"
uid=501(saket) gid=501(saket) groups=501(saket)
saket user details successfully processed
[root@ngelinux ~]# 

Leave a Reply

avatar
  Subscribe  
Notify of