I've probably tooted about this before, but I don't know why this isn't standard.

It's just so obvious, at least to me. ;)

~ $ type mcd mcd is a function mcd () { [[ -n $1 ]] && mkdir "$1" && cd "$1" }

#shell #UnixShell #ShellScripting #sh #bash #ksh #mksh

@rl_dane I don't get it
@joel @rl_dane i have the same i think ... Need to check mine

@joel @rl_dane

mine is actually a bit different

mkd() { [[ -n $1 ]] && mkdir -p "$1" && cd "$_" }

@hyde @joel

It's totally valid, but I'm curious as to your reasoning for using $_ instead of $1. I only ever use that variable interactively. ;)

Actually, no. I use !$, which is a bash-ism, and not actually a variable. ;)

@rl_dane Actually, I dont know ... I use it often in terminals and I must have been a habit I have 🤷‍♂️
@joel
@hyde @rl_dane @joel $_ is a perl thing at least where I think it just resolve to the last set variable, or something like that, you often use it in for loops and stuff.

@sotolf

It's the last argument of the previous command executed.

In this case there isnt a real advantage, but sometimes when you don't want to type a long word, it can help

@rl_dane @joel