In bash, I know of 3 "args from previous command" shortcuts. They are:
- !^ → first arg, spaces preserved;
- $_ → last arg, spaces not preserved;
- !* → all args, spaces preserved;
So are there any more arg vars/shortcuts like that? :)
the $_ is useful when I call a file with one command, that's say in a different [long named] directory, then want to call it again in my next command [i.e. $ stat a\ b\ c/sub/folder/example.txt; mv $_ .
], except when there are spaces in it, it does not work.
Why doesn't $_ preserve spaces? To see what I mean type this:
$ echo "1" "One String Quoted"; for i in $_; do echo \"$i\"; done
and compare with
$ echo 1 2 "3 4 5";
then press enter then: $ for i in !*; do echo \"$i\" done;
Can you also explain why you have to press enter ^ then do the "for" loop in order for !* to work? [And why the $_ works without having to press enter (AKA, you can use ";" to combine the commands)]