SC14-Handbook

EXERCISE TIME

Okay cool. Now that you've learnt so much about shell scripting ( Yeah, I know it was boring ) , it's time to put that knowledge that you acquired into something substantial.

So lets test ourselves and see how strong we are in shell scripting.

Psst. Dont worry , the volunteers are here to help you out.

Question 1 ) How to write shell script that will add two nos, which are supplied as command line argument, and if this two nos are not given show error and its usage

Question 2 ) Write Script to find out biggest number from given three nos. Nos are supplies as command line argument. Print error if sufficient arguments are not supplied.

Question 3 ) Write Script, using case statement to perform basic math operation as follows

  • addition
  • subtraction x multiplication / division

Cool. So now that you've worked them out. Lets actually see how good your scripting was.

And if you werent able to solve it, dont freak out. It happens to be every budding programmer. The more you try, the better you learn

Here are the answers to the questions above. Dont refer them if you have not tried the questions.

[Solution to Question 1][1]

[Solution to Question 2][2]

[Solution to Question 3][3]

A few more exercises maybe ?

Question 4 ) Write script to print given number in reverse order, for eg. If no is 123 it must print as 321.

Question 5 ) Write script to print given numbers sum of all digit, For eg. If no is 123 it's sum of all digit will be 1+2+3 = 6.

Solutions :

[Question 4][4]

[Question 5][5]

Did you have a nice time solving these ? Dying to learn more about shell script ?

Well. Here are a few links that will help you

Keep learning.

http://www.freeos.com/guides/lsst/ch08.html http://www-h.eng.cam.ac.uk/help/tpl/unix/scripts/node16.html http://parallel.vub.ac.be/documentation/linux/unixdoc_download/exercises/Scripts.Ex.html