Tutorial 5 - Tutorial 5 In this tutorial, we are going to...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Tutorial 5 In this tutorial, we are going to familiarize ourselves with shell programming. We will have some hands-on experience with ready to use scripts. We will also create some scripts ourselves as exercise. Use Vi, Emacs or Pico for editing the scripts. Login to one of the following Unix servers: cs1.utdallas.edu cs2.utdallas.edu Use PuTTY or Xmanager for logging on as you have learnt in Tutorial 1 . For some basic constructs which we are going to use, you can consult the book for reference. The page numbers are given below: read : page 353 exit : page 356 if : page 358 test : page 359 while : page 373 break : page 377 First example script: Hello World In our first example, we will write a simple script which will print the string "Hello World!" to the terminal. Open your favorite Unix editor and type in the following script: #!/bin/bash # hello world shell script echo Hello World! Everything on the right of a '#' is comment. The first line is a special comment, it is called the She-Bang line. It must reside in every shell script. It contains the path of the shell after a '!'. Save the file as "hello_world.sh" and then from the terminal assign it execute permission like this: {cs1:~} chmod +x hello_world.sh Run the script:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
{cs1:~} hello_world.sh Hello World! {cs1:~} Note that a new line is printed after the "Hello World!" string. How can you prevent echo from printing the new line? Fibonacci number Now we will run a script which calculates n-th Fibonacci number where n will be provided as input when prompted. User input 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Output 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 Here is the script: #!/bin/bash # Fibonacci number shell script # It takes input one number and show Fibonacci number of that serial # Prompts for an input
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/12/2009 for the course CS 3375 taught by Professor Kendracooper during the Fall '08 term at University of Texas at Dallas, Richardson.

Page1 / 7

Tutorial 5 - Tutorial 5 In this tutorial, we are going to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online