0%

Chapter 7

Commands, Configuration, and Errors

Identify Your Shell and Find Help

Two windows can look identical while a different is reading your commands in each one. That matters the moment you follow shell-specific advice, because a command, an option, or a help page that works in one may simply not exist in the other.

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 and open Bash. The same observation works in your own terminal even when its default is different.

Read the session, not the setting

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.

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 shellA useful help route
Bashhelp cd for a Bash built-in
zshman zshbuiltins, then search for cd
PowerShellGet-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.

  1. Identify the shell that is actually running, using the method for your system.

  2. Open the help page for that shell’s directory-changing command.

  3. 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.