Sheet 11.doc

advertisement
CST334
Tutorial Sheet 11
Shell Customizing
Read Chapter 5 & 13
LOGIN AND SHELL INITIALIZATION (STARTUP) FILES, p530-532
1.
Three types of start up files:
system initialization file /etc/profile
login initialization file
.bash_profile
shell initialization file
.bashrc
2.
Three types of variables: environment (or keyword) variables,
user-created variables, positional parameters
PREDEFINED (KEYWORD) VARIABLES, p521 - 530
3.
There are many key word variables already defined that are used to customize your working
environment. All of them are upper case words, and include:
(view them all by typing
set)
HOME
PATH
TERM
USER
PWD
MAIL
SHELL
4.
5.
5a.
6.
Path name of your home directory
Directories where shell is to look for command's
The termcap code for your terminal
Your user name
Your current working directory
Path name of your system mailbox
Path name of shell
View the value of the key word variable by typing: echo $HOME, echo $USER,
echo $TERM
Change the value of the key word variable by typing, for example: TERM=vt100
Do not use spaces between =
Do not change anything else!
Export a variable to all sub shells
export $TERM
(setenv in other shells)
However, if you want a change to be permanent, you must make the change in your
.bash_profile file. If you change this file, it won't take effect until you log in again. But
if you type source .bash_profile or . .bash_profile you can make the changes take effect
immediately.
SEARCH PATH
7.
8.
echo $PATH
: = directory separator :: = current directory
Show how to add the cst334 directory to your PATH variable.
Show how to add the working directory to your PATH variable
USER DEFINED VARIABLES p504 - 514
9.
You can create your own variables by giving the variable a name and a value
stuff = /home/cst334
echo $stuff
ls $stuff
cd $stuff
HISTORY p532-536 The history mechanism allows users to look at recent commands
10.
Control how many commands are remembered:
HISTSIZE=200
12.
To view a numbered list of recent commands: history
13.
To look at commands 1000 to 1010: fc -1 1000 1010
13.
To re execute a command you have typed before, all you have to do is type:
!231 where 231 is the command number that you want to repeat
14.
To re execute the previous command, you can type !!
ALIAS p170 - 176
15.
17.
18.
19.
20.
make an alias (shortcut) to a commonly repeated command by typing: alias e='emacs'
make an alias for chmod ug+x called simply x:
alias x='chmod ug+x'
You want to cd to cs80 often, so you make an alias for it:
Aliases can be made permanent by entering them in your .bashrc file.
Before making an alias, check that the alias name is not already taken:
which name
ACTIVITIES
View the current setting of your environment variables:
View the current settings one page at a time:
Read the screen: what is HOME variable currently set to:
View the setting of your HOME variable:
View the setting of your USER variable
View the setting of your PS1 variable
(this controls what your Unix prompt looks like)
A)
B)
C)
D)
E)
F)
G)
GG)
H)
I)
J)
K)
L)
M)
N)
O)
P)
PP)
Q)
R)
set
set | more
echo $HOME
echo $USER
echo $PS1
ls –a or ls .*
cp .bash_profile .bash_profile.BAK
cp .bashrc .bashrc.BAK
Edit your start up file using Emacs, vi or Joe:
emacs .bash_profile
Add a comment on the first line:
# last modified XX/XX/XX (date)
Add a message to be displayed each time you log in
Go to the bottom of the file, then type
echo "now starting Linux..."
Save the file and quit the editor
Try out the new login file,
source .bash_profile
View the current prompt symbol:
echo $PS1
IMPORTANT save the prompt symbol in a new variable psave=$PS1
No spaces between =
Try out another prompt:
PS1=# or PS1 = "may I help you…"
Don't be alarmed! now type ls
[it's still the same old Unix, just a new prompt]
Reset to the old prompt symbol
PS1=$psave
Edit your .bash_profile file
Add the following line to create your own variable stuff
stuff =/home/cst334
Save the file, exit, try out the new changes
source .bash_profile
Try out your new variable:
echo $stuff
cd $stuff
pwd cd
So this is another way to get to the cst334 directory
A better way: make an alias that automatically takes you there.
alias go334="cd /home/cst334"
Try out the alias:
go334
pwd
cd
View your history file history
Read the screen, look for the command number of the source command you typed in L
Execute again the
source .bash_profile command, using history
!cmd_num
Re-execute the previous command
!!
View your (hidden) start up files:
Make a backup of your startup files:
Download