KEMBAR78
Shellscripting | ODP
SHELL PROGRAMMING
Introduction to Shell   You communicate with a UNIX system through a command program known as a  shell . The shell interprets the commands that you type on the keyboard.  There are many different shells available for UNIX computers, and on some systems you can choose the shell in which you wish to work.\ You can use shell commands to write simple programs (scripts) to automate many tasks
Introduction to Shell When you log in, you are in one of five shells. 1. Bourne Shll –  /bin/sh  – Steve Bourne (On AT & T UNIX) 2. Bourne Again SHell –  /bin/bash  – Improved Bourne shell (On Linux) 3. C Shell –  /bin/csh  – Bill Joy (On BSD UNIX) 4. TC Shell –  /bin/tcsh  (On Linux) 5. Korn Shell –  /bin/ksh  – David Korn (On AT & T UNIX) The system administrator determines which shell you start in.
Basics Definition:  Shell is an agency that sits between the user and the UNIX system.  Description: Understands all user directives and carries them out.  Processes the commands issued by the user.
Shell Scripts Example: script.sh #! /bin/sh # script.sh: Sample Shell Script echo “Welcome to Shell Programming” echo “Today’s date : `date`”  echo “This months calendar:” echo “My Shell :$ SHELL”
Shell Variables Environmental Variables: Some global environment variables are, HOME  Path to your home directory HOST  The hostname of your system LOGNAME  The name you login with PATH  Paths to be searched for  commands SHELL  The login shell you’re using PWD   Present working directory
Local Shell Variables A variable assignment is of the form  variable=value , but its evaluation requires the $ as prefix to the variable name. count=5 echo $count total=$count You can assign value of one variable to another variable echo $total Note: There should not be any space around =.  i.e. if we say x =5 then the shell interprets x as command running with the =5 as argument!
Shell scripts accept arguments from the command line.  Run non interactively  Arguments are assigned to special shell variables (positional parameters). Represented by $1, $2, etc;  Position variables
Position variables
#! /bin/sh echo “Program Name : $0” echo “No of Arguments : $#” echo “Arguments are : $*” $ chmod +x 2.sh $ 2.sh A B C o/p     Program Name : 2.sh   No of Arguments : 3   Arguments are : A B C Position variables
Bourne Shell Programming Control structures if … then for … in while  until case break and continue
if … then Structure if  test-command   then commands fi Example: if test  “$word1”  =  “$word2”  then  echo “Match” fi
for: Looping with a List for is also a repetitive structure.  Syntax: for variable in list  do Commands done  Note: list here comprises a series of character strings. Each string is assigned to variable specified.
A partial list of built-in bg, fg, jobs job control break, continue change the loop cd, pwd working directory echo, read display/read eval scan and evaluate the command exec execute a program exit   exit from current shell export, unset export/ remove a val or fun test compare arguments
kill sends a signal to a process or job set  sets flag or argument shift promotes each command line argument times displays total times for the current shell and  trap traps a signal type show whether unix command, build-in, function umask file creation mask wait waits for a process to terminate. ulimit  print the value of one or more resource limits A partial list of built-in
System Scripts some system scripts  /etc/init.d/syslog /etc/init.d/crond
Powerful scripts can be built using the excellent features offered in shell programming. A preliminary insight on shell programming has been offered here.  Scripts can make use of these as well as advanced features to help programmers/users of system to work with efficiency and  ease. conclusions:
Thank you

Shellscripting

  • 1.
  • 2.
    Introduction to Shell You communicate with a UNIX system through a command program known as a shell . The shell interprets the commands that you type on the keyboard. There are many different shells available for UNIX computers, and on some systems you can choose the shell in which you wish to work.\ You can use shell commands to write simple programs (scripts) to automate many tasks
  • 3.
    Introduction to ShellWhen you log in, you are in one of five shells. 1. Bourne Shll – /bin/sh – Steve Bourne (On AT & T UNIX) 2. Bourne Again SHell – /bin/bash – Improved Bourne shell (On Linux) 3. C Shell – /bin/csh – Bill Joy (On BSD UNIX) 4. TC Shell – /bin/tcsh (On Linux) 5. Korn Shell – /bin/ksh – David Korn (On AT & T UNIX) The system administrator determines which shell you start in.
  • 4.
    Basics Definition: Shell is an agency that sits between the user and the UNIX system. Description: Understands all user directives and carries them out. Processes the commands issued by the user.
  • 5.
    Shell Scripts Example:script.sh #! /bin/sh # script.sh: Sample Shell Script echo “Welcome to Shell Programming” echo “Today’s date : `date`” echo “This months calendar:” echo “My Shell :$ SHELL”
  • 6.
    Shell Variables EnvironmentalVariables: Some global environment variables are, HOME Path to your home directory HOST The hostname of your system LOGNAME The name you login with PATH Paths to be searched for commands SHELL The login shell you’re using PWD Present working directory
  • 7.
    Local Shell VariablesA variable assignment is of the form variable=value , but its evaluation requires the $ as prefix to the variable name. count=5 echo $count total=$count You can assign value of one variable to another variable echo $total Note: There should not be any space around =. i.e. if we say x =5 then the shell interprets x as command running with the =5 as argument!
  • 8.
    Shell scripts acceptarguments from the command line. Run non interactively Arguments are assigned to special shell variables (positional parameters). Represented by $1, $2, etc; Position variables
  • 9.
  • 10.
    #! /bin/sh echo“Program Name : $0” echo “No of Arguments : $#” echo “Arguments are : $*” $ chmod +x 2.sh $ 2.sh A B C o/p  Program Name : 2.sh No of Arguments : 3 Arguments are : A B C Position variables
  • 11.
    Bourne Shell ProgrammingControl structures if … then for … in while until case break and continue
  • 12.
    if … thenStructure if test-command then commands fi Example: if test “$word1” = “$word2” then echo “Match” fi
  • 13.
    for: Looping witha List for is also a repetitive structure. Syntax: for variable in list do Commands done Note: list here comprises a series of character strings. Each string is assigned to variable specified.
  • 14.
    A partial listof built-in bg, fg, jobs job control break, continue change the loop cd, pwd working directory echo, read display/read eval scan and evaluate the command exec execute a program exit exit from current shell export, unset export/ remove a val or fun test compare arguments
  • 15.
    kill sends asignal to a process or job set sets flag or argument shift promotes each command line argument times displays total times for the current shell and trap traps a signal type show whether unix command, build-in, function umask file creation mask wait waits for a process to terminate. ulimit print the value of one or more resource limits A partial list of built-in
  • 16.
    System Scripts somesystem scripts /etc/init.d/syslog /etc/init.d/crond
  • 17.
    Powerful scripts canbe built using the excellent features offered in shell programming. A preliminary insight on shell programming has been offered here. Scripts can make use of these as well as advanced features to help programmers/users of system to work with efficiency and ease. conclusions:
  • 18.