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.

Slides:



Advertisements
Similar presentations
Shell Scripting Printing; Loops and Logic printf: formatted print printf is a more standardized method to print text to the screen. It can be used instead.
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`
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Shell Programming Software Tools. Slide 2 Shells l A shell can be used in one of two ways: n A command interpreter, used interactively n A programming.
CS 497C – Introduction to UNIX Lecture 33: - Shell Programming Chin-Chih Chang
Integer variables #!/bin/csh # sum of numbers from $argv[1] to $argv[2] set low = $argv[1] set high = $argv[2] set sum = 0 set current = $low while ( $current.
Information Networking Security and Assurance Lab National Chung Cheng University 1 if condition Condition is defined as: "Condition is nothing but comparison.
Shell Programming Learning Objectives: 1. To understand the some basic utilities of UNIX File 2. To compare UNIX shell and popular shell 3. To learn the.
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
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.
Lab 8 Shell Script Reference:
Shell Control Structures CSE 2031 Fall August 2015.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
LINUX Shell Scripting Advanced Issues
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
1 Operating Systems Lecture 3 Shell Scripts. 2 Shell Programming 1.Shell scripts must be marked as executable: chmod a+x myScript 2. Use # to start a.
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 5 Bourne Shells Scripts By C. Shing ITEC Dept Radford University.
Keyword Shell Variables The shell sets keyword shell variables. You can use (and change) them. HOME The path to your home directory PATH Directories where.
CMPSC 60: Week 6 Discussion Originally Created By: Jason Wither Updated and Modified By: Ryan Dixon University of California Santa Barbara.
#!/bin/sh echo Hello World cat Firstshellscript.sh Firstshellscript.sh.
Shell Script Yingying Wang. Basic Commands Good resources Google is your friend
This slide deck is for LPI Academy instructors to use for lectures for LPI Academy courses. ©Copyright Network Development Group Module 9 Basic Scripting.
1 © 2001 John Urrutia. All rights reserved. Chapter 10 using the Bourne Again Shell.
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
Shells. Variables MESSAGE="HELLO WORLD" echo $MESSAGE MESSAGE="HELLO WORLD $LOGNAME" echo $MESSAGE MESSAGE="HELLO WORLD $USER" echo $MESSAGE.
(A Very Short) Introduction to Shell Scripts CSCI N321 – System and Network Administration Copyright © 2000, 2003 by Scott Orr and the Trustees of Indiana.
Shell Programming Learning Objectives: 1. To understand the some basic utilities of UNIX File 2. To compare UNIX shell and popular shell 3. To learn the.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
Shell Script2 Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
CISC3130 Spring 2013 Fordham Univ. 1 Bash Scripting: control structures.
1 Unix/Linux commands and shell programming-Part 2 (Dr. Mohamed El Bachir Menai)
Perl Lab #11 Intro to Perl Debbie Bartlett. Perl Lab #1 2 Perl Practical Extraction and Report Language –or- Pathologically Eclectic Rubbish Lister Created.
UNIX Shell Script (2) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Flow Control. The order in which commands execute in a shell script is called the flow of the script. When you change the commands that execute based.
Lab 8 Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
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.
Shell script – part 2 CS 302. Special shell variable $0.. $9  Positional parameters or command line arguments  For example, a script myscript take 2.
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.
Assigning Values 1. $ set One Two Three [Enter] $echo $1 $2 $3 [Enter] 2. $set `date` [Enter] $echo $1 $2 $3 [Enter] 3. $echo $1 $2 $3 $4 $5 $6 [Enter]
Compunet Corporation Introduction to Unix (CA263) Round and Round By Tariq Ibn Aziz Dammam Community College.
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.
#!/bin/sh 2002/07/26 Jaeho Shin. Interface between user and the operating system sh, bash, csh, tcsh, ksh, … What is a “Shell”? OSuser Shell.
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.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Linux Essentials Chapter 12: Creating Scripts. Chapter 12 Outline Beginning a shell script Using commands Using arguments Using variables Using conditional.
Linux Administration Working with the BASH Shell.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Shell Control Structures CSE 2031 Fall June 2016.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
Bash Shell Scripting 10 Second Guide.
Shell Control Structures
Unix Scripting Session 4 March 27, 2008.
Shell Script Assignment 1.
Agenda Control Flow Statements Purpose test statement
What is Bash Shell Scripting?
Unix Scripting Dave Yearke
awk- An Advanced Filter
Presented by, Mr. Satish Pise
Shell Control Structures
Shell Control Structures
Chapter 5 Bourne Shells Scripts
Introduction to Bash Programming, part 3
Unix Scripting Session 2 March 13, 2008.
Review The Unix Shells Graham Glass and King Ables,
Presentation transcript:

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 Try it as follows: $ chmod 755 isnump_n $ isnump_n 5 5 number is positive $ isnump_n number is negative $ isnump_n./ispos_n : You must give/supply one integers

looping $ cat > testfor for i in do echo "Welcome $i times" done Run it above script as follows: $ chmod +x testfor $./testfor

example $ cat > for2 for (( i = 0 ; i <= 5; i++ )) do echo "Welcome $i times" done

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=$1 fi 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

Test data sname Sr.No Name 11 Vivek 12 Renuka 13 Prakash 14 Ashish 15 Rani smark Sr.No Mark

cut $cut -f2 sname Vivek Renuka Prakash Ashish Rani $cut -f1 sname

Paste $ paste sname smark 11 Vivek Renuka Prakash Ashish Rani 15 67

tr $ tr "[a-z]" "[A-Z]" hi i am Vivek HI I AM VIVEK what a magic WHAT A MAGIC {Press CTRL + C to terminate.}

awk Before learning more about awk create data file using any text editor or simply vi:inventoryinventory egg order 4 cacke good 10 cheese okay 4 pen good 12 floppy good 5 After crating file issue command $ awk '/good/ { print $3 }' inventory 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