Lesson 1 · Unit 01
The shell, set up
How a name is found, aliases and functions, startup files, history search
What you practise
PATHand how a command is found, environment variables and where they are set, aliases and functions, startup files, history search
Try a question from this lesson
Pick one
A real date program sits in /usr/bin. The first line defines a shell function with the same name. What does the second line print?
date() { echo "my date"; }
dateCorrect answer
my date
Why
The shell checks its own definitions before it searches the disk, so the function wins and the program in /usr/bin is never reached. A name is not tied to a file: it is whatever the shell finds first.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Where a name comes from
Bash looks for a name in this order: alias, function, builtin (part of the shell itself, like cd), then each folder on PATH, left to right. The first hit wins.
When a command surprises you, ask the shell what it found: type name, or type -t name for a one-word answer.
type -t cd
type -t grep
greet() { echo hi; }
type -t greetConcept
Startup files
Aliases and functions vanish when the shell closes, so they go in a file bash reads at startup.
A login shell (what you get over SSH) reads ~/.bash_profile. Any other interactive shell, such as a new terminal tab, reads ~/.bashrc. A script reads neither.
Keep shortcuts in the rc file and make the profile load it.
# ~/.bash_profile
export PATH="$HOME/bin:$PATH"
source ~/.bashrc10 more exercises in the app
- 2× type the answer
- 4× multiple choice
- 2× fill the blanks
- 1× true or false
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.