> For the complete documentation index, see [llms.txt](https://til.yulrizka.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.yulrizka.com/unix/reusing-last-command-argument.md).

# reusing last command argument

```bash
$ echo 1
1
$ echo 2
2
$ echo 3
3
$ echo 4
4
$ echo 5
5
```

use `alt + .` will reuse the last program argument in descending order

```
$ echo (press alt + .)
$ echo 5 (press alt + . again)
$ echo 4 (press alt + . again)
...
```

## selective arguments

* `!:1` gives you the first argument
* `!:2-3` gives you 2nd and third argument and
* `!:-3` gives you binary name + first 3 arguments

```
$ echo 1 2 3 4 5
$ echo !:1 # -> echo 1
$ echo 1 2 3 4 5
$ echo !:2-3 # -> echo 2 3
$ echo 1 2 3 4 5
$ echo !:-3 # -> echo echo 1 2 3
```
