Upcoming SlideShare
Loading in...5







Total Views
Views on SlideShare
Embed Views



1 Embed 13 13



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Intro_Unix_Ppt Intro_Unix_Ppt Presentation Transcript

    •   The user interface to the operating system
    • Functionality: – Execute other programs – Manage files – Manage processes
    •   Full programming language
    • A program like any other – This is why there are so many shells
    What is Shell?
  • Shell Scripts
    • A shell script is a regular text file that contains shell or UNIX commands
    • – Before running it, it must have execute permission:
    • chmod +x filename
    • A script can be invoked as:
    • – ksh name [ arg … ]
    • – ksh < name [ args … ]
    • – name [ arg …]
  • First Script
    • When a script is run, the kernel determines which shell it is written for by examining the first line of the script
    • – If 1st line starts with #!pathname-of-shell, then it invokes pathname and sends the script as an argument to be interpreted
    • – If #! is not specified, the current shell assumes it is a script in its own language
    • leads to problems
  • Sample Example
    • #!/bin/sh
    • echo Hello World
  • Variables
    • #!/bin/bash # declare STRING variable STRING=&quot;Hello World&quot; #print variable on a screen echo $STRING How to execute it: chmod +x
    • Now you are ready to execute your first bash script:
    • ./
  • Reading User Input
    • #!/bin/bash
    • echo -e &quot;Hi, please type the word: c &quot;
    • read word
    • echo &quot;The word you entered is: $word&quot;
    • echo -e &quot;Can you please enter two words? &quot;
    • read word1 word2
    • echo &quot;Here is your input: &quot;$word1&quot; &quot;$word2&quot;&quot;
    • echo -e &quot;How do you feel about bash scripting? &quot;
    • # read command now stores a reply into the default build-in variable $REPLY
    • read
    • echo &quot;You said $REPLY, I'm glad to hear that! &quot;
    • echo -e &quot;What are your favorite colours ? &quot;
    • # -a makes read command to
    • read into an array read -a colours
    • echo &quot;My favorite colours are also ${colours[0]}, ${colours[1]} and ${colours[2]} &quot;
  • read statement
    • Use to get input (data from user) from keyboard and store (data) to variable. Syntax: read variable1, variable2,...variableN
    • Following script first ask user, name and then waits to enter name from the user via keyboard. Then user enters name from keyboard (after giving name you have to press ENTER key) and entered name through keyboard is stored (assigned) to variable fname.
  • read statement (continued..)
    • $ vi sayH # #Script to read your name from key-board # echo &quot;Your first name please:&quot; read fname echo &quot;Hello $fname, Lets be friend!“
    • Run it as follows: $ chmod 755 sayH $ ./sayH
    • Your first name please: vivek Hello vivek, Lets be friend!
  • Arithmetic Comparisons -lt < -gt > -le <= -ge >= -eq == -ne !=
  • String Comparison = equal != not equal < less than > greater than -n s1 string s1 is not empty -z s1 string s1 is empty