bash (2)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 & ps --forest
Type these commands, one per line:
date pwd cd df --human who
Write a single echo command that shows the value of
the variables HISTSIZE, HISTFILE, and
HISTFILESIZE. (Hint: use $)
Show the last five commands you’ve typed by entering history 5
Use the fc command to show every command you have typed
since the most recent ps command, and only those
commands.
Use the fc command with the -s option to
re-execute that ps command.
Use ! to reference the most recent df
command you did. Do not use the history number.
Use ! to redo the sixth preceding command.
Use ! to redo the most recent command that contained
the letters wd.
Type touch file05 to create a file.
Use ! with the s modifier to re-execute
that command, only substituting the 5 with a 6
(see page 303)
We are skipping the vi editing mode on pages 305-306.
Type ls file and then the TAB key three times to see all filenames beginning with file.
Type echo $OLDP followed by the TAB key to see variable completion in action.
We are skipping the material on pages 309 to 311
Create an alias dfh which is an alias for
df --human
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
dirA and dirB.
Use the 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 /user).
Now type this: shopt -s cdspell
Now type cd /user again. It’s magic!
Now turn off the cdspell option. (page 319)
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 send it to the instructor.