Presented by, Mr. Satish Pise

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
Advertisements

Linux Shell Script. Shell script The first line is used to specify shell program #!/bin/sh Variables variable=“text” variable=0 variable=`program arguments`
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 1 Simple Rails Template
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Using factors to find the prime factorization of a number
Information Networking Security and Assurance Lab National Chung Cheng University 1 if condition Condition is defined as: "Condition is nothing but comparison.
CS 497C – Introduction to UNIX Lecture 34: - Shell Programming Chin-Chih Chang
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
UNIX Shell Scripting > Echo “A quick how-to”. What is shell scripting? Interpreted (non-compiled) language Slower compared to compiled languages Much.
Shell Programming. Shell Scripts (1) u Basically, a shell script is a text file with Unix commands in it. u Shell scripts usually begin with a #! and.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
Chapter 15 Introductory Bash Programming
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Chapter Nine Advanced Shell Scripting1 System Programming Advanced Shell Scripting.
1 Procedures Blocks of code which can be called from anywhere in a program Enable us to avoid needless repetition of the same code Can take parameters.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 11: Shell.
Shell Programming Any command or a sequence of UNIX commands stored in a text file is called a shell program. It is common to call this file a command.
#!/bin/sh echo Hello World cat Firstshellscript.sh Firstshellscript.sh.
Beyond sh Not everyone is as fond of UNIX as most other people. The tutorial talks about the dark side of UNIX.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
Shell Script Yingying Wang. Basic Commands Good resources Google is your friend
A Practical Guide to Fedora and Red Hat Enterprise Linux Unit 5: Scripting in Linux Chapter 27: Programming the Bourne Again Shell By Fred R. McClurg Linux.
1 © 2001 John Urrutia. All rights reserved. Chapter 10 using the Bourne Again Shell.
Chapter 2 User_defined Function. Chapter Goals In this chapter, you’ll learn all about PHP functions, including how : to create and invoke them, pass.
CSC 4630 Meeting 5 January 31, Next Time Enhance the steps that you used to clean the Moby Dick chapter to create a shell script that takes any.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Xuan Guo Chapter 5 The Bourne Shell Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Notes by Michael.
LING 408/508: Programming for Linguists Lecture 5 September 9 th.
Lab 8 Overview Apache Web Server. SCRIPTS Linux Tricks.
Introduction to Bash Shell. What is Shell? The shell is a command interpreter. It is the layer between the operating system kernel and the user.
If condition1 then statements elif condition2 more statements […] else even more statements fi.
Group, group, group One after the other: cmd1 ; cmd2 One or both: cmd1 && cmd2 Only one of them: cmd1 || cmd2 Cuddling (there):( cmd1 ; cmd2 ) Cuddling.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Shell Scripting What is Shell Programming? Putting UNIX commands in a file Seldom used where speed is important Often used to manipulate files To create.
Chapter 5 The Bourne Shell Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Notes by Michael Weeks.
© Prepared By: Razif Razali 1 TMK 265: UNIX SYSTEM CHAPTER 8: USER INPUT.
2 nd Intro to Shell Scripting. Dates for Last Week of Class Homework 7 – Due Tuesday 5/1 by midnight Labs 7 & 8 or late ones – 8 is extra credit – Due.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Experiment No. 13 Presented by, Mr. Satish Pise. Write a shell script which checks disk space and store the value to the variable and display it. #!/bin/sh.
1 UNIX Operating Systems II Part 2: Shell Scripting Instructor: Stan Isaacs.
Shell Scripting September 27, 2004 Class Meeting 6, Part II * Notes adapted by Lenwood Heath from previous work by other members of the CS faculty at Virginia.
Let’s COUNT In tenths
Bash vs. dash PLUG West PLUG North JP Vossen bashcookbook.com.
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
Hello Educational presentation.
Bash Shell Scripting 10 Second Guide.
CIRC Winter Boot Camp 2017 Baowei Liu
How to link a test to a launcher (in this case a shell launcher)
CSC 352– Unix Programming, Fall 2012
Shell Scripting March 1st, 2004 Class Meeting 7.
By Jonathan Rinfret CREATING A BASH SCRIPT By Jonathan Rinfret
What is Bash Shell Scripting?
LING 408/508: Computational Techniques for Linguists
Agenda Functions: What are functions? / Purpose of Functions
  30 A 30 B 30 C 30 D 30 E 77 TOTALS ORIGINAL COUNT CURRENT COUNT
Counting
Copyright © – Curt Hill Bash Flow of Control Copyright © – Curt Hill.
Counting
Presented by, Mr. Satish Pise
Prepared by, Mr. Satish Pise
Chapter 5 The Bourne Shell
CSC 352– Unix Programming, Fall, 2011
Essential Shell Programming
CST8177 Scripting 2: What?.
Introduction to Bash Programming, part 3
Basic shell scripting CS 2204 Class meeting 7
Presented by, Mr. Satish Pise
Presented by, Mr. Satish Pise
Presented by, Mr. Satish Pise
Presentation transcript:

Presented by, Mr. Satish Pise Experiment No. 9 Presented by, Mr. Satish Pise

Command Line Parameters ($1 $2 ..) # sh addem 10 30 This example passes two command line parameters (10 and 30) to the script addem Example 1 #!/bin/bash # using one command line parameter value1=10 total=$[ $value1 * $1 ] echo $total

Example 2 #!/bin/bash # testing string parameters echo Hello $1, glad to meet you. # sh test3 satish

Example 3 #!/bin/bash # handling lots of parameters total=$[ ${10} * ${11} ] echo The tenth parameter is ${10} echo The eleventh parameter is ${11} echo The total is $total $ sh test4 1 2 3 4 5 6 7 8 9 10 11 12

Counting parameters ($#) Example 1 #!/bin/bash # getting the number of parameters echo There were $# parameters supplied. $ sh test8 There were 0 parameters supplied. $ sh test8 1 2 3 4 5

Being Shifty Example 1 #!/bin/bash # demonstrating the shift command count=1 while [ -n "$1" ] do echo "Parameter #$count = $1" count=$[ $count + 1 ] shift done $ sh test13 rich barbara katie jessica

Example 2 #!/bin/bash # demonstrating a multi-position shift echo "The original parameters: $*" shift 2 echo "Here’s the new first parameter: $1" $ sh test14 1 2 3 4 5

Processing simple options Example 1 #!/bin/bash # extracting command line options and values while [ -n "$1" ] do case "$1" in -a) echo "Found the -a option";; -b) param="$2" echo "Found the -b option, with parameter value $param" shift 2;; -c) echo "Found the -c option";; --) shift break;; *) echo "$1 is not an option";; esac shift done count=1 for param in "$@" echo "Parameter #$count: $param" count=$[ $count + 1 ] $ sh test17 -a -b test1 –d