A simple Bash question to test your terminal skills

Can you combine the following commands into one without using the directory name twice:

mkdir api
cd api

The answer is in the first comment of this post :slight_smile:

1 Like
mkdir api && cd $_
2 Likes

I can save a character here!

mkdir api; cd $_

3 Likes

I can save one more char, though I wouldn’t recommend it for readability reasons :slight_smile:
mkdir api;cd $_

4 Likes

Permanent function (.bashrc):
function mkcd { command mkdir $1 && cd $1 }

zsh:
take 'dirname'

3 Likes