1 / 11

Shell scripting

Shell scripting. Number check. vi isnump_n #!/bin/sh # # Script to see whether argument is positive or negative # if [ $# -eq 0 ] then echo "$0 : You must give/supply one integers" exit 1 fi if test $1 -gt 0 then echo "$1 number is positive" else echo "$1 number is negative" fi. run.

cayla
Download Presentation

Shell scripting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Shell scripting

  2. Number check • vi isnump_n#!/bin/sh## Script to see whether argument is positive or negative#if [ $# -eq 0 ]thenecho "$0 : You must give/supply one integers"exit 1fiif test $1 -gt 0thenecho "$1 number is positive"elseecho "$1 number is negative"fi

  3. run • Try it as follows:$ chmod 755 isnump_n$ isnump_n 55 number is positive$ isnump_n -45 -45 number is negative$ isnump_n./ispos_n : You must give/supply one integers

  4. looping • $ cat > testforfor i in 1 2 3 4 5doecho "Welcome $i times"done • Run it above script as follows:$ chmod +x testfor$ ./testfor

  5. example • $ cat > for2for ((  i = 0 ;  i <= 5;  i++  ))do  echo "Welcome $i times"done

  6. case • $ cat > car## if no vehicle name is given# i.e. -z $1 is defined and it is NULL## if no command line argif [ -z $1 ]then  rental="*** Unknown vehicle ***"elif [ -n $1 ]then# otherwise make first arg as rental  rental=$1fi • case $rental in   "car") echo "For $rental Rs.20 per k/m";;   "van") echo "For $rental Rs.10 per k/m";;   "jeep") echo "For $rental Rs.5 per k/m";;   "bicycle") echo "For $rental 20 paisa per k/m";;   *) echo "Sorry, I can not gat a $rental for you";;esac

  7. Test data • sname • Sr.No     Name11          Vivek12          Renuka13          Prakash14         Ashish15         Rani • smark • Sr.No    Mark11          6712          5513          9614          3615          67

  8. cut • $cut -f2 snameVivekRenukaPrakashAshishRani • $cut -f1 sname1112131415

  9. Paste • $ paste sname smark11    Vivek      11    6712    Renuka   12    5513    Prakash 13    9614    Ashish   14     3615    Rani      15     67

  10. tr • $ tr "[a-z]" "[A-Z]" hi i am VivekHI I AM VIVEKwhat a magicWHAT A MAGIC • {Press CTRL + C to terminate.}

  11. awk • Before learning more about awk create data file using any text editor or simply vi:inventory • egg       order   4cacke   good   10cheese  okay   4pen       good  12floppy   good   5 • After crating file issue command$ awk '/good/ { print $3 }' inventory10125 • awk utility, select each record from file containing the word "good" and performs the action of printing the third field (Quantity of available goods.). Now try the following and note down its output.$ awk '/good/ { print $1 " " $3 }' inventory

More Related