Configuring the bash shell
Notes:
Bash Configuration files:
-
You can setup files that automatically configure your working environment
every time you login. The three major configuration files for the bash shell
are:
-
/etc/profile - generic system-wide profile
-
.bash_profile - personal profile that is processed every time you login
-
.bashrc - setup file processed every time you open a non-login shell
Modifying the prompt:
-
In a command interface, the prompt is what you see on the screen when the
system is waiting for you to enter your next command.
-
Under the bash shell, the primary prompt is stored in a variable called PS1.
-
To change the prompt you use the command: PS1='value'
eg: PS1='type something! '
-
Some of the codes that can go in the prompt are:
-
\d the date (day-of-the-week month day)
-
\h the hostname (without the domain)
-
\n start a new line
-
\u the current username
-
\w the working directory
Aliases.
-
An alias lets you setup typing shortcuts. An example of an alias would be:
alias byebye='logout'
When you type byebye, bash will interpret this as logout.
-
To cancel the alias, use the command:
unalias byebye
-
To view any aliases that are already defined for your account, use the command:
alias
Bash Shell Options:
-
There are a number of options that can be set; one of the most useful is
the noclobber option. If noclobber is on, then you cannot accidentally overwrite
a file using redirection.
-
The command to turn on the noclobber option is: set -o noclobber
-
The command to turn off the noclobber option is:
Exercises:
-
Answer the following questions about the current setup:
-
What is stored in the current .bash_profile?
-
What is your prompt?
-
What is your path?
-
What is your umask value?
-
Are there any aliases set up?
-
Change the prompt as follows:
-
Change the prompt to -->
-
Change the prompt to 2 lines:
Get going
Enter your next command>
-
Change the prompt to: your working directory followed by a $
-
When you change directories, does the prompt change to the new directory
name? (it will if you've set it correctly)
-
Logout and login again. Was the new prompt saved or has it gone back to $
?
-
Setup aliases as follows:
-
Setup dir as an alias for ls -l . Type dir. Did you get a long directory
listing? __
-
Is "rename" a valid command in floppix? _____
Make rename an alias for mv. Now you should be able to use the command:
rename readme ignoreme
This should change the name of the readme file. Did it work?
-
Does the rm command ask for confirmation before a file is deleted? Test it
out.
-
copy the passwd file to mypass: cp /etc/passwd mypass
-
remove the passwd file: rm mypass
-
did you receive a confirmation request before mypass was deleted? ___
-
Create the following alias: rm='rm -i'
-
Test your alias:
-
copy the passwd file to mypass: cp /etc/passwd mypass
-
remove the passwd file: rm mypass
-
did you receive a confirmation request before mypass was deleted?
-
Test the noclobber option
-
Turn on the noclobber option.
-
Create the file flist using the command: ls -l > flist
-
Repeat: ls -l > flist
-
Did you get an error message?
-
Turn off the noclobber option.
-
Enter the command: ls -l /etc > flist
-
This time the command should overwrite flist with a newer version. Did it?
-
Point to remember:
-o turns noclobber ON
+o turns noclobber OFF
-
Create a .bash_profile that:
-
sets the background color of the screen to black.
-
sets the prompt to the name of the working directory followed by $ .
-
sets the search path to /usr/bin and /bin .
-
sets dir as an alias for ls -l .
-
configures rm to prompt for confirmation before deleting a file.
-
prevents bash from overwriting an existing file when redirecting output
-
Test your profile - logout and login again.
Copyright ©
L.M.MacEwan