Linux+ 1.5.1: The shell environment
A directory of your own on the PATH for good, which startup files bash runs for login and non-login shells, and the history shortcuts.
Before you start
The lab creates user alex (password Lab-Pass-1, shell bash). Do the
tasks as alex: sudo -iu alex or su - alex. On the RHEL family alex's
login startup file is ~/.bash_profile; on Ubuntu it's ~/.profile.
Tasks
- Create
~/bin/hi, a script that printshi fromand its own name (echo "hi from $0"), and make it executable. Add$HOME/binto the front ofPATHin alex's login startup file, so thathiworks in every new login shell. - Add the line
echo bashrc ranto~/.bashrcandecho profile ranto the login startup file. Startbash(non-login) andbash -l(login) and see which lines each one prints. Leave the lines in place until you've runle-lab check, then remove them. - Practice history: run
ls /etc/ssh, thencd !$, then!!, then press Ctrl+r and typelsto find the first command. Not graded.
Hints
mkdir -p ~/bin,printf '#!/bin/bash\necho "hi from $0"\n' > ~/bin/hi,chmod +x.echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bash_profile(or~/.profile), thensourceit;which hi.- Both families already put
~/binon the PATH: AlmaLinux's default~/.bashrcadds it, and Ubuntu's~/.profileadds it at login if it exists. Theexportline is how you'd add any other directory. - bash runs only the first of
~/.bash_profile,~/.bash_loginand~/.profilethat it finds for a login shell.