79403162

Date: 2025-01-31 15:11:16
Score: 0.5
Natty:
Report link

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!

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: user29448665