Shell Function

noun

say it: “SHEL FUNK-shun” /ˈʃɛl ˈfʌŋkʃən/

A few shell commands kept under one name, so typing the name runs them all; it can use the words typed after the name.

What is a shell function?

A shell function keeps a few commands under one name, so typing the name runs them all. Where an alias only swaps one word for another, a function can use what you type after its name: "$1" is the first word, "$2" the second. Keep the ones you like in ~/.bashrc, so every new terminal has them.

mkcd() {
  mkdir -p "$1" && cd "$1"
}
mkcd photos/2026/november

In a sentence

  • “Sam wrote a shell function called mkcd that makes a folder and moves into it in one step.”
  • “An alias couldn't use the folder name typed after it, so Sam turned it into a shell function with "$1".”

Level: Apprentice · More Unix terms at this level

Updated