Re:How to navigate directories faster with Bash (2015)
by alsetmusic on Thursday April 22, 2021 @08:45AM
(#26902096)
Wait, now I'm confused. I have:
mkcd() { mkdir -p "$@" && cd "$_"; }
Can someone please detail the differences between $! and $_? (Apologies if I'm missing something obvious)
Re:How to navigate directories faster with Bash (2015)
by tyingq on Thursday April 22, 2021 @08:59AM
(#26902228)
$ echo "test" > /dev/null && echo !$
/dev/null
$ echo "test" > /dev/null && echo $_
test
Re:How to navigate directories faster with Bash (2015)
by karatinversion on Thursday April 22, 2021 @09:05AM
(#26902288)
You're thinking of $_ and !$, and I think they are equivalent - $_ is explicitly the last argument of the previous command, whereas !$ is a history expansion command. ! starts a new history expansion command, and $ is a word designator for the last word of the selected history entry. To quote man bash, " If a word designator is supplied without an event specification, the previous command is used as the event."
I would not that !$ is a bash-ism, whereas $_ works at least on zsh and ksh as well as bash.
Re:How to navigate directories faster with Bash (2015)
by forgotmypw17 on Thursday April 22, 2021 @03:58PM
(#26907436)
alias tcd='a=`date +%s`;mkdir "$a" && cd "$a"'
Re:How to navigate directories faster with Bash (2015)
by gpspake on Thursday April 22, 2021 @08:32AM
(#26901988)
Yep, first thing I add to my dotfiles when I don't have it haha
Re:How to navigate directories faster with Bash (2015)
by cutthegrass2 on Thursday April 22, 2021 @07:54AM
(#26901705)
+1, I do the same.
Re:How to navigate directories faster with Bash (2015)
by bunsenhoneydew on Thursday April 22, 2021 @08:05AM
(#26901771)
Me too
mkcd() { mkdir -vp "$1" && cd "$1"; }