24.07.2018 Views

Bash-Beginners-Guide

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Bash</strong> <strong>Guide</strong> for <strong>Beginners</strong><br />

3.7. Summary<br />

The <strong>Bash</strong> environment can be configured globally and on a per user basis. Various configuration files are used<br />

to fine-tune the behavior of the shell.<br />

These files contain shell options, settings for variables, function definitions and various other building blocks<br />

for creating ourselves a cosy environment.<br />

Except for the reserved Bourne shell, <strong>Bash</strong> and special parameters, variable names can be chosen more or less<br />

freely.<br />

Because a lot of characters have double or even triple meanings, depending on the environment, <strong>Bash</strong> uses a<br />

system of quoting to take away special meaning from one or multiple characters when special treatment is not<br />

wanted.<br />

<strong>Bash</strong> uses various methods of expanding command line entries in order to determine which commands to<br />

execute.<br />

3.8. Exercises<br />

For this exercise, you will need to read the useradd man pages, because we are going to use the /etc/skel<br />

directory to hold default shell configuration files, which are copied to the home directory of each newly added<br />

user.<br />

First we will do some general exercises on setting and displaying variables.<br />

1. Create 3 variables, VAR1, VAR2 and VAR3; initialize them to hold the values "thirteen", "13" and<br />

"Happy Birthday" respectively.<br />

2. Display the values of all three variables.<br />

3. Are these local or global variables?<br />

4. Remove VAR3.<br />

5. Can you see the two remaining variables in a new terminal window?<br />

6. Edit /etc/profile so that all users are greeted upon login (test this).<br />

7. For the root account, set the prompt to something like "Danger!! root is doing stuff in \w", preferably<br />

in a bright color such as red or pink or in reverse video mode.<br />

8. Make sure that newly created users also get a nice personalized prompt which informs them on which<br />

system in which directory they are working. Test your changes by adding a new user and logging in<br />

as that user.<br />

9. Write a script in which you assign two integer values to two variables. The script should calculate the<br />

surface of a rectangle which has these proportions. It should be aired with comments and generate<br />

elegant output.<br />

Don't forget to chmod your scripts!<br />

Chapter 3. The <strong>Bash</strong> environment 55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!