Mac Terminal · Command Line Guide

audience developer
level all
topic Terminal
subtopic Use

How to fix 'Command not found: $'

How to fix command not found: $ on Mac. For zsh or bash. What the $ (dollar sign) means in the Mac Terminal on the command line.

You'll encounter the error command not found: $ when you try to run a command in the Mac Terminal. This error occurs when you accidentally enter a placeholder prompt character in the "shell", or command line interpreter (zsh or bash). This guide explains what the $ (dollar sign) means and how to fix the error.

It's a simple error, based on a misunderstanding of a convention, that's easy to fix. A surprising number of people make the error, perhaps because the convention is not well-understood.

Skip to the end "Just for fun" for an interesting technical solution to the problem.

Before you get started

You'll see command not found: $ when you are using the Mac terminal application. I prefer Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and worth a try.

The error 'zsh: command not found: $'

To get the error, you enter a $ (dollar sign) character followed by a space (and more characters, probably a command you saw in a tutorial or README):

$ <something>

And this is the error you'll see:

zsh: command not found: $

The error message shows that Zsh shell ("the command line interpreter") cannot find a command named $. Zsh takes the first character before a space as a command and ignores anything that comes after the space.

If you see an error that begins with bash... you are using the Bash shell.

bash: command not found: $

If you are using the Bash shell, you likely have an older version of the macOS. Check macOS and update macOS and switch to the Zsh shell.

How to fix 'command not found: $'

Here's how to fix the error:

  1. Try entering a command without the $ (dollar sign) character.
  2. The Terminal should respond with a different message (sometimes a different error).

You may be trying to run Homebrew (zsh: command not found: brew), Python (zsh: command not found: python), Pip (zsh: command not found: pip), or any number of other commands.

It starts with a misunderstanding

The $ character in tutorials indicates a command prompt. It is not meant to be typed in. It shows where you are expected to type a command.

Here’s an example to clarify:

Tutorial Example:

$ ls

What You Should Type:

ls

The $ is simply a placeholder to show that a command should be entered into the terminal. Here’s a brief explanation:

  • $ is the command prompt indicator.
  • ls is a command you'll type to list files or directory contents.

What the command prompt looks like

Here's a screenshot of the Mac Terminal showing the prompt you see when you first open the Terminal application:

the $ dollar sign comand prompt in the Mac Terminal

You won't see the $ (dollar sign) in the Mac Terminal on newer Macs. Instead you'll see a % percent sign as a command prompt indicator.

By default, unless the prompt has been customized in a shell configuration file, you'll see the following elements in the prompt:

  • username
  • an @ sign
  • device name
  • current directory (the ~ tilde symbol indicated the user home directory)
  • a % percent sign (the command prompt indicator)

Why do tutorials show a '$' dollar sign?

There are two reasons that tutorials show the $ dollar sign:

  • It's an indicator of command line usage
  • It distinguishes between input and output

Tutorial authors follow a convention. When the author shows a reader the $ at the beginning of a line, the author is signaling text that follows is a command to be entered in the terminal. By showing the prompt, it’s clear what is user input versus system output. When an example includes a mix of commands and system output, with commands on multiple lines, the $ distinguishes user input from command output.

The first time a tutorial author uses the convention, it's good if they say, "The $ denotes a command to enter in a terminal; copy everything after the $".

On newer Macs, the prompt is a '%' sign

The $ prompt was introduced in the Bourne Shell (sh) in 1979, for Version 7 Unix, which became a foundation for many modern operating systems, including macOS. Developers have adopted new command line interpreters, or shells, over time, including the C Shell (csh) and Bash (Bourne Again Shell), which was a default on macOS until macOS 10.15 Catalina introduced the Z shell (zsh).

On newer Macs, the Z shell's default command prompt is the % sign. You'll see the % sign, not the $ sign, as a command prompt in the Mac Terminal, which can be confusing for beginners who expect the $ sign from books or tutorials.

When the prompt is a '#' sign

The $ sign is not the only command prompt. You will see the # (hash or octothorpe) sign if you log in as "root" or superuser in the Terminal. With an admin account and password, the shell allows you to gain privileged access, in which case you'll see the # sign as a command prompt, reminding you that you're no longer logged in as an ordinary user.

Customizing the command prompt

Command prompts can be customized. Developers often enhance their prompts to include additional information like the current directory, username, or hostname.

Just for fun

There's an interesting technical solution to the problem. Set an alias for the $ sign:

alias '$'=''

Enter this once in the Terminal and the problem will disappear the next time you try it. To make the alias permanent, you'll need to use a text editor to configure the shell and add the alias alias '$'='' to the ~/.zshrc file. It's a complicated technical solution for a beginner but as an exercise, it's a good introduction to the everyday challenges of a developer.

If you try the alias trick, you can also try:

$ echo "works!"

It contains a surprise that leads to more learning about the command line. Enjoy!

Acknowledgments

Thanks to my esteemed colleagues at lobste.rs for comments and feedback, especially antonmedv for the alias trick.

What's next

My mac.install.guide is a trusted source of installation guides for professional developers. Take a look at the Mac Install Guide home page for tips and trends and see what to install next.