M01: Introduction to Operating Systems
TU3: Installing specific purpose software
ASIX1
Pract. Exerc. 1: Introduction to shell scripts  2-05-17

GENERAL CONDITIONS
1- Deadline: 14-05-2017. No exercise sent to us beyond  this date will be accepted. On the 15th of May we will provide you with a proper answer of these exercises.
2- Create a tar.gz file 
including every script.
3- Send a tar.gz file attached to an e-mail with the following specifications:
     a) E-mail address:
cf(at)collados.org or jordi.binefa(at)fje.edu depending who is your teacher.
     b) File Name:
          b.1) ASIX1 (Catalan): asix1_surname_name_m01tu03pr1.tar.gz
          b2.) DAW1 (English): daw1_surname_name_m01tu03pr1.targfz
    c) Subject:
        
c.1) ASIX1 (Catalan): asix1_surname_name_m01tu03pr1
         c.2)
DAW1 (English): daw1_surname_name_m01tu03pr1
 
4- Make your scripts individually.

DOCUMENTATION ABOUT SHELL SCRIPTING

1.- Introduction
    1.1.-
What is a Linux shell?
    1.2.- What is a shell program or script? // What is a shell program or script?
    1.3.- Interpreted vs Compiled programs
    1.4.- Why to write a shell script?  // Why to write a shell script?
    1.5.- What is a shebang (or sha-bang)?
    1.6.- Writing your first script and getting it to work
    1.7.- Different ways to invoke a script
2.-Variables
    2.1.- Variables: environment variables and user defined variables.
    2.2.- Displaying current values of your environment variables
    2.3.- User defined variables.
    2.4.- Accessing to a variable value.
    2.5.- Local and global shell variables and the export command // The export command
    2.6.- Positional parameters (also called arguments)
    2.7.- Bash variables are untyped
    2.8.- Bash special variables. $? variable.
3.- Special characters
    3.1.- List of special characters
    3.2.- Comments
    3.3.- Quotes
    3.4.- Redirection
4.- Some important commands
    4.1.- exit
    4.2.- echo . Another web page with useful information about the echo command..
    4.3.- read
    4.4.- expr
    4.5.- test // File test operators // Other comparision operators
5.- if...then...else...fi structure
    5.1.- if..then..else..fi // if..then..else..fi
    5.2.- if..then..fi
    5.3.- brackets
    5.4.- Nested if/then Condition Tests
6.- case statement
    6.1.- case stament
7.- Loop staments
    7.1.- while statement
    7.2.- until statement
    7.3.- for statement
    7.4.- break and continue commands
8
.-Useful links
    8.1.-
http://tldp.org/LDP/abs/html/
    8.2.-http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/index.html
    8.3.- http://www.freeos.com/guides/lsst/index.html
    8.4.- http://bash.cyberciti.biz/guide/Main_Page
    8.5.- http://www.dartmouth.edu/~rc/classes/ksh/welcome.html#top
9- Some small examples
    9.1.- Some small examples    
   
PRACTICAL EXERCISES

1- Write a script to create a new group in your system. Your script will terminate returning an exit code exit code equal to 0 if everything works fine but, if your script fails to create the new group, it will terminate returning an exit code equal to 1. Save your script with the following name: script01.sh. Run and check if your script works.

2- Write a script to show the following informations about the user who runs:
a) Personal folder
b) Default shell
c) Language
d) User name
e) PATH
Your script will terminate returning an exit code exit code equal to 0.Save your script with the following name: script02.sh. Run and check if your script works.

3- Write a script which displays all numbers from 10 to 90 in a first column, their double values in a second column and their square values in a third column. Your script will terminate returning an exit code equal to 0.Save your script with the following name: script03.sh. Run and check if your script works

4- Write a script which will show the user with a menu with 4 options: a) Add, b) Substract, c) Multiply, c) Divide. Once the user has chosen an option, your script will ask him/her a first operand and a second operand . Your script has to execute the operation asked at the beginning, using the given operands. Your script will terminate returning an  exit code exit code equal to 0.Save your script with the following name: script04.sh. Run and check if your script works

5- Write a script that shows the contents of the scripts script01.sh to script04.sh, writing the script name before showing its content. Your script will terminate returning an exit code exit code equal to 0.Save your script with the following name: script05.sh. Run and check if your script works.

6- Modify script04.sh. Add an option to ask the user if he/she wants to start again from the beginning. If the user answers s, your scripts should show again the menu.
If the user does not answer s, your scripts should terminate returning an  exit code exit code equal to 0 Save your script with the following name: script06.sh. Run and check if your script works.

7- Write a script called script07.sh that:
a) Firstly, it tries to download  loginteller.tar.gz  which is a file stored in a software repository  whose URL is http://www.collados.org/asix1/m01/tu3/
loginteller.tar.gz. if your script fails to download loginteller.tar.gz, it will terminate returning an exit code equal to 1 and showing: "File not found".
b
) Secondly,  the contents of loginteller.tar,gz will be extracted. After extracting its contents, two new files should have been created: loginteller.c and Makefile.

Show the main features (owner, permissions,size...) of both files.
c)
Thirdly, the contents of loginteller.c will be displayed.
d) Finally, loginteller.c will be compiled  running the command gcc loginteller -o loginteller 2> /dev/null. If loginteller is succesfully compiled, your scripts  will display the main features (owner, permissions,size...) of loginteller if your script fails to compile loginteller.c, it will terminate returning an exit code equal to 2 and showing: "File not compiled".
Your
script must terminate returning an exit code equal to 0 if everything works fine.   

ASIX1: List of students and assigned scripts