Assignment 10.doc

advertisement
CST 334
ASSIGNMENT 10
Chapter 5&13
DUE: next Wed
Working with bash
1. Log on to mlc104. Run the chsh command, and change your default shell to
/bin/ksh. Close the terminal window and re-login, and confirm that you're
running ksh with the ps command. Then use chsh to change back to /bin/bash.
2. Run the command that gives you a list of all the environment variables that are
currently set.
3. Using a pipe to the wc command, find out how many environment variables are
currently set.
4. Create a new environment variable called MYVAR and set its value to "myvalue".
Repeat step 3 to ensure that the number of variables increased by 1. Use the
command export MYVAR to allow MYVAR to be used by sub-programs of the shell.
Verify that this step worked by printing out the value of MYVAR on the terminal,
start a new shell by typing bash, then print the new variable again. It should still
read "myvalue" Exit from the new shell.
5. Try changing your command prompt to: (save it first by psav=$PS1)
a) "prompt> "
b) nothing
c) your username
d) the output of the date command followed by "$ " (tricky)
Then restore the original command prompt.
6. There is a program in the cst334 directory called hello . Copy the the program
hello to your home directory. Try running the program from your home directory
by typing hello at the prompt. This won't work; you need to specify the path to
run the program - try this now. Create a directory called bin in your home
directory. Copy the hello file to your bin directory. View your PATH variable to
make sure this directory is in your PATH (it should be). Now type hello and it
works! Change directories to any directory on the system and type hello, it will
still work.
7. Create and try out some aliases for yourself.
'll' for 'ls -l'
'la' for 'ls -la | more'
'psall' for 'ps -ef'
'm' for 'more'
'up' for 'cd ..'
'back' for 'cd -'
'sterra' for 'ssh mpc82a30@terra.mpc.edu'
8. Now open a new terminal window. Check on whether your environment variable
MYVAR or some of the aliases you created are present. They shouldn't work in this
new shell because you only made the changes to the first shell. You need to place
these commands in a login script in order for them to take effect whenever you
start a new shell…as described in the next 3 steps.
9. Back in the first shell, open up the file .bash_profile in your home directory.
Add the line:
echo ".bash_profile was read"
10. Now experiment to find out when this file is used.
when you open a new terminal window? ___________
when you start a new shell within an existing one? _________
when you ssh to another machine
(for this just ssh into mlc104 again,
ssh mlc104)
11. Now add the definition of variable MYVAR to your .bash_profile, along with the
export command from step 4. Log out and log in, and verify that the new variable
is still present.
12. To gather up the aliases, use the history command to list the recent commands
you have issued. Figure out in what range of command numbers your environment
variable and alias commands fall, and use the fc -l (fixed command) command
to list only those commands (you can put numbers after the -l to make a range).
Make sure you are in your home directory. Now run the same fc command, but
redirect its output to concatenate at the end of your .bashrc file.
13. Edit .bashrc (using vi) to remove the command numbers and any extraneous
commands and tabs.
14. Now start a new login shell by ssh'ing into any machine (ssh into mlc104
again) Were your commands executed? _______ What about when you start a
new shell from the old one (by just typing bash on the command line)? ______
15. Your modified .bashrc and .bash_profile files will be collected electronically as
evidence of homework completion.
Download