CSIS-80 LECTURE 10Chapter10: Bourne Again Shell

LOGIN AND SHELL INITIALIZATION (STARTUP) FILES

1.Two types of start up files: login initialization file .bash_profile

shell initialization file.bashrc

2. Three types of variables: environment (or keyword) variables,

user-created variables, positional parameters

KEYWORD VARIABLES, p328 - 332

3.There are many key word variables used to customize your working environment. All of them are upper case words, and include: view them all by typing set

HOMEPath name of your home directory

PATHDirectories where shell is to look for command's

TERMThe termcap code for your terminal

USERYour user name

PWDYour current working directory

MAILPath name of your system mailbox

SHELLPath name of shell

4.View the value of the key word variable by typing: echo $HOME, echo $USER,

echo $TERM

5.Change the value of the key word variable by typing, for example: TERM=vt100

Do not use spaces between =Do not change anything else!

5a.Export a variable to all sub shells export $TERM (setenv in other shells)

6.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 echo $PATH : = directory separator :: = current directory

7.Show how to add the cs80 directory to your PATH variable.

8.Show how to add the working directory to your PATH variable

USER DEFINED VARIABLES

9.You can create your own variables by giving the variable a name and a value

stuff = /home/mpc80/cs80echo $stuff

ls $stuff cd $stuff

HISTORYThe 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

15.make an alias (shortcut) to a commonly repeated command by typing: alias e='emacs'

17.make an alias for chmod ug+x called simply x: alias x='chmod ug+x'

18.You want to cd to cs80 often, so you make an alias for it:

19.Aliases can be made permanent by entering them in your .bashrc file.

20.Before making an alias, check that the alias name is not already taken: which name

ACTIVITIES

View the current setting of your environment variables:set

View the current settings one page at a time:set | more

Read the screen: what is HOME variable currently set to:

View the setting of your HOME variable:echo $HOME

View the setting of your USER variableecho $USER

View the setting of your PS1 variable echo $PS1

(this controls what your Unix prompt looks like)

A)View your (hidden) start up files:ls –a or ls .*

Make a backup of your startup files: cp .bash_profile .bash_profile.BAK

cp .bashrc .bashrc.BAK

B)Edit your start up file using Emacs, vi or Joe: emacs .bash_profile

C)Add a comment on the first line:# last modified XX/XX/XX (date)

D)Add a message to be displayed each time you log in

Go to the bottom of the file, then type

echo "now starting Linux..."

E)Save the file and quit the editor

F)Try out the new login file,source .bash_profile

G)View the current prompt symbol: echo $PS1

GG)IMPORTANT save the prompt symbol in a new variable psave=$PS1

No spaces between =

H)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]

I)Reset to the old prompt symbol PS1=$psave

J)Edit your .bash_profile file

K)Add the following line to create your own variable stuff

stuff =/home/mpc80/cs80

L)Save the file, exit, try out the new changessource .bash_profile

M)Try out your new variable:echo $stuff cd $stuffpwd cd

So this is another way to get to the cs80 directory

N) A better way: make an alias that automatically takes you there.

alias go80="cd /home/mpc80/cs80"

O)Try out the alias: go80pwdcd

P)View your history file history

PP)Read the screen, look for the command number of the source command you typed in L

Q)Execute again the source .bash_profile command, using history !cmd_num

R)Re-execute the previous command!!