Views:
2,897β
Votes: 5β
Tags:
command-line
bash
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/1256426
Title:
What does ${_[0]} mean in bash?
ID:
/2020/07/05/What-does-____0__-mean-in-bash_
Created:
July 5, 2020
Edited: July 5, 2020
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
As others have mentioned ${_[0]}
is extra typing for ${_}
which in turn can be abbreviated into $_
as it is most commonly used.
As mentioned previously it is a variable that contains the last parameter of the last command used. A practical application is like this:
$ ll /etc/lsb-release
-rw-r--r-- 1 root root 105 Feb 20 2019 /etc/lsb-release
$ cat $_
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"
In the first command the last parameter is /etc/lsb-release
. In the second command the parameter is $_
, which repeats /etc/lsb-release
so you donβt have to retype it.