Read everything before doing anything!
Please go through this exercise once to try everything out; when you turn in your script file, I don’t want to see every bad attempt you made to get something to work. I just want to see the results of working commands. Hint: Write down what you think the correct answers are, then try them. Once you get everything working, go through all the steps and record them in a script file.
Type script bash2 to start recording commands.
Type these commands:
sleep 15 &
Type these commands, one per line:
date pwd cd df --human who
Write a single
echo command that shows the value of the variables
HISTFILESIZE. (Hint: use
Show the last five commands you’ve typed by entering history 5
fc command to show every command you have typed since the most recent
ps command, and only those commands.
fc command with the
-s option to re-execute that
! to reference the most recent
df command you did. Do not use the history number.
! to redo the sixth preceding command.
! to redo the most recent command that contained the letters
Type touch file05 to create a file.
! with the
s modifier to re-execute that command, only substituting the
5 with a
6 (see pages 316 and 317)
We are skipping the
emacs editing modes on pages 318-319.
Type ls file and then the TAB key three times to see all filenames beginning with
Type echo $OLDP followed by the TAB key to see variable completion in action.
We are skipping the material from the bottom of page 321 to the middle of page 324.
Create an alias
dfh which is an alias for
Type dfh to see if it worked.
Show a list of all aliases currently available.
Type cd to return to your home directory.
The next few examples are very important. Type this command:
alias dirA="echo Working Directory is $PWD"
Because the text is enclosed in double quotes, the variable $PWD is evaluated right then and there, as the alias is created, and the alias will contain the name of your home directory.
Now type this command:
alias dirB='echo Working Directory is $PWD'
Because the text is enclosed in single quotes, the alias will contain the literal string
$PWD; it will not be evaluated right away.
Change to a different directory: cd /etc
Type dirA; since the home directory name was expanded when the alias was built, it shows you your home directory name, which is wrong.
Type dirB; since the
$PWD is in single quotes, it gets evaluated when the alias gets used.
Use a single
unalias command to get rid of the aliases
alias command with no arguments to verify that those aliases are gone.
This one is just too cool to pass up: type cd /user; it should give you an error message (it’s the
/usr directory, not
Now type this: shopt -s cdspell
Now type cd /user again. It’s magic!
Now turn off the
cdspell option. (pages 331-332)
Confirm it by typing cd /user again, and getting an error message.
Type exit to stop recording your commands in the script file.
Change the name of your script file to the form
lastname_firstname_bash2.script and upload it to Moodle.