I have been trying to install a Nagios package and stumbled upon these weird bash expansions on a guide here. Can someone help me understand what do the expansions mean? A wiki link would also be helpful for future reference.root@z:~> wget http://mathias-kettner.de/download/check_mk-1.1.7i5.tar.gzroot@z:~> tar zxvf !#:troot@z:~> chown -R root:root !$:r:r && chmod -R o-w !$:r:r && cd !$:r:rroot@z:~/check_mk-1.1.7i5> ./setup.sh
What does !# (exclamation hash), !$:r:r (exclamation dollar colon r), !#:t (exclamation hash colon t) mean in the below bash commands?
bash;command history
These are bash history expansion keywords. They select a line from the shell history and reinsert (portions of) it, possible after modification. The site you linked to does a reasonable job explaining them, but it doesn't describe all of them.tar zxvf !#:tdoesn't actually make sense: !# selects the line typed so far, but that's tar zxvf and we don't want to re-use any of that. It should betar zxvf !$:twhich selects the last portion of the previous line (!$), which is the URL given to wget, and takes the filename portion (:t, for tail  strictly speaking it's whatever's left after the last directory separator, /, which happens to work nicely with URLs).Thenchown -R root:root !$:r:rselects last portion of the previous line, drops the file extension (:r  strictly speaking, it removes whatever's after the last ., including the .) twice, which gives the directory name (assuming the tarball contains a directory with the same name as the tarball's base name). The chmod and cd commands proceed in the same way.