Write the following script with the name mkdir_and_go_into_it.sh
:
#!/usr/bin/env bash
if [[ "$0" == *mkdir_and_go_into_it.sh ]] || [ "$1" = "" ]; then
echo "Usage: mdgo <directory>"
else
mkdir --parents "$1"
cd "$1"
fi
Make it executable (chmod +x mkdir_and_go_into_it.sh
).
Then add to your ~/.bashrc
file:
alias mdgo="source path/to/mkdir_and_go_into_it.sh"
(Replace path/to
with the directory where you store the script.)
Open another Bash instance and try it out:
Enter..
mdgo test123
=> A new directory "test123" has been created and you are in it!