Chapter 7
Commands, Configuration, and Errors
Identify Your Shell and Find Help
Two
So before taking anyone’s word about what to type: find out what is actually running. The terminal beside this lesson follows your account preference: Windows opens PowerShell Core, while
Read the session, not the setting
Ask the shell to print the name it was started with. In the hosted lesson this reports Bash; on your own Mac it may report zsh:
echo $0
In an interactive terminal, $0 holds the current shell’s name. You will see bash, zsh, or something similar. A result such as -zsh still means zsh; the leading dash only marks it as a login shell.
Ask the shell to print the name it was started with. In the hosted lesson this reports Bash:
echo $0
In an interactive terminal, $0 holds the current shell’s name. You will see bash, zsh, or something similar. A result such as -bash still means Bash; the leading dash only marks it as a login shell.
Ask PowerShell to describe itself:
$PSVersionTable.PSVersion
A version value coming back confirms PowerShell is interpreting your commands. The hosted terminal uses PowerShell Core. On your own Windows machine, if that same text produces an error, you are probably in Command Prompt, and the error is useful evidence rather than a problem.
You will also see advice to check $SHELL on macOS or Linux. Be careful with it. $SHELL names your account’s default login shell, which is not the same question. Start Bash from inside zsh and $SHELL keeps saying zsh while Bash reads everything you type.
Ask the current shell when the distinction matters. The prompt symbol is an even weaker clue, since $, %, and > are all configurable and people configure them.
Ask the shell you have
Each shell has a local help route: man and command-specific help on macOS and Linux, and Get-Help in PowerShell. Once you know which shell you are in, use the route that belongs to it:
| Current shell | A useful help route |
|---|---|
| Bash | help cd for a Bash built-in |
| zsh | man zshbuiltins, then search for cd |
| PowerShell | Get-Help Set-Location |
These answer a much narrower question than a web search, and they cannot hand you syntax from a different shell. Half the frustration beginners have with command lines comes from applying a correct answer to the wrong shell.
Do not change your default shell for this lesson. That affects every future session, and nothing here needs it.
Practice: identify and confirm
Use the terminal beside this lesson, leave it as it is, and do not start another shell inside it.
Identify the shell that is actually running, using the method for your system.
Open the help page for that shell’s directory-changing command.
Write down two things: the shell’s name, and the first line or title of the help page you got.
Those two facts are the whole exercise. If someone hands you a command that does not work, being able to state exactly which shell you are in is often enough to solve it on the spot.
A learner's $SHELL value is /bin/zsh, but echo $0 prints bash. Which shell is reading commands in this terminal now?
You paste a command from a tutorial and the shell reports a syntax error near an unexpected token, while the same command works fine for the person who sent it. What is worth checking first?
You have the first troubleshooting fact: which shell is interpreting your commands. The next question is what it does with the first word you type.