Basics of Shell Programming. What’s Shell? It’s acts an interface between the user and OS (kernel).It’s known as “ command interpreter”. When you type.

Slides:



Advertisements
Similar presentations
#!/bin/sh Jaeho Shin. Interface between user and the operating system sh, bash, csh, tcsh, ksh, … What is a Shell? OSuser Shell.
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`
More Shell Programming Software Tools. Slide 2 Keyword Shell Variables l The shell sets keyword shell variables. You can use (and change) them. HOME The.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
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.
Operating Systems Review. User Computer, including HW and SW.
23-Jun-15Advanced Programming Spring 2002 bash Henning Schulzrinne Department of Computer Science Columbia University.
Lecture 01CS311 – Operating Systems 1 1 CS311 – Lecture 01 Outline Course introduction Setting up your system Logging onto the servers at OSU with ssh.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
Shell Script Examples.
CSCI6303 – Principles of I.T. Fall  Student will become familiar with scripting in shell using Linux/Ubuntu  Student will write a script and execute.
2 $ command Command Line Options ls –a –l hello hi Command Arguments.
Shell Control Structures CSE 2031 Fall August 2015.
CTEC 1863 – Operating Systems Shell Scripting. CTEC F2 Overview How shell works Command line parameters –Shift command Variables –Including.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
Using the Bash Shell. Linux Shell Options Linux provides a range of options for shells. bash –The GNU Bourne Again Shell (bash) bsh – The Bourne Shell.
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.
Writing Shell Scripts ─ part 1 CSE 2031 Fall September 2015.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Shell Scripting Todd Kelley CST8207 – Todd Kelley1.
July 17, 2003Serguei A. Mokhov, 1 Shells and Shell Scripts COMP 444/5201 Revision 1.3 January 25, 2005.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Essential Shell Programming by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
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.
CS465 - UNIX The Bourne Shell.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
UNIX/LINUX SHELLS.  “A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
LINUX programming UNIT-2 1. INDEX UNIT-IV PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Working with Bourne shell L1 1-2.
Shells. Variables MESSAGE="HELLO WORLD" echo $MESSAGE MESSAGE="HELLO WORLD $LOGNAME" echo $MESSAGE MESSAGE="HELLO WORLD $USER" echo $MESSAGE.
Week 8: Linux / ubuntu Dr. I. H. Shah. / CSCS 301 Fall 2009.
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
CSCI 330 UNIX and Network Programming Unit IX: Shell Scripts.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Shell Control Statements and More
Jozef Goetz, expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.
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]
#!/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.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Linux Administration Working with the BASH Shell.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Shell Control Structures CSE 2031 Fall June 2016.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Computer Programming Batch & Shell Programming 9 th Lecture 김현철 컴퓨터공학부 서울대학교 2009 년 가을학기.
CS 350 Lecture 3 UNIX/Linux Shells by İlker Korkmaz and Kaya Oğuz.
Shell Control Structures
Department of Computer Engineering
Lecture 7 Introduction to Shell Programming
Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Agenda Bash Shell Scripting – Part II Logic statements Loop statements
LINUX System : Lecture 5 (English-Only Lecture)
Lecture 9 Shell Programming – Command substitution
The Linux Operating System
Shell Script Assignment 1.
Agenda Control Flow Statements Purpose test statement
John Carelli, Instructor Kutztown University
Writing Shell Scripts ─ part 1
Shell Programming.
Linux Shell Script Programming
Bash Scripting CS 580U - Fall 2018.
Essential Shell Programming
Presentation transcript:

Basics of Shell Programming

What’s Shell? It’s acts an interface between the user and OS (kernel).It’s known as “ command interpreter”. When you type ls : shell finds cmd (/usr/bin). shell runs cmd. you receive the output.

What’s Shell Program? It’s collections of executables or commands placed in a file and executed. It provides user an option to execute a command based on some condition. It provides conditional and control statements.(if,for,while,switch-case etc )

Types of Shell Bourne shell (sh) C shell (csh) TC shell (tcsh) Korn shell (ksh) Bourne Again SHell (bash)

Simple Shell Programs

#print date and time - today.sh echo "Today is:" date Save it as today.sh Run: sh today.sh

#sample.sh #!/bin/sh # assign a value: a="hello world" # now print the content of "a": echo "A is:" echo $a

#ex-2 grep word in a file - grep_ex.sh echo "Enter the search string:" read string echo "Enter the file name:" read filename grep -n "$string" $filename

If statement Type 1: if condition is true then do this if Type 2: if condition is true then do this else do that if

#if stmt - if_ex.sh echo "Enter the search string:" read string echo "Enter the file name:" read filename grep -n "$string" $filename # $? gives exit status of last command if [ $? -eq 0 ] then echo " Yes,the word present in the file" else echo "No,word not present" fi

o/p : ~]$ sh if_ex.sh Enter the search string: date Enter the file name: today.sh 2:date Yes,the word present in the file o/p: ~]$ sh if_ex.sh Enter the search string: year Enter the file name: today.sh No,word not present

Passing values from command line: $0 - Program name $1 - First argument $2 - Second arg. $# - No.of arg $? - Exit status

#print date and time and cmd arg - today_1.sh echo "Today is:" date echo “No.of arg:”$# echo “Program name:”$0 o/p: ~]$ sh today_1.sh Today is: Fri Mar 7 00:28:27 IST 2008 “No.of arg:”0 “Program name:”today_1.sh

#grep using cmd line -grep_ex2.sh echo "Entered search string is:"$1 echo "Entered file name :"$2 grep -n "$1" $2 # $? gives exit status of last command if [ $? -eq 0 ] then echo " Yes,the word present in the file" else echo "No,word not present" fi

o/p: ~]$ sh grep_ex2.sh date today.sh Entered search string is:date Entered file name :today.sh 2:date Yes,the word present in the file

#simple for loop for i in do echo "==>$i" done #for loop - for_ex.sh for file in *. do echo “Hi” done #simple for loop-3 for (( j = 1 ; j <= 5; j++ )) do echo -n "$j " done

#print files with extension.c for file in *.c do echo "Filename==>$file" #place any no.of cmds cp $file /home/oss/cprogs done

while loop – syntax while [ condition ] do code block; done

#while_ex.sh verify="n" while [ "$verify" != y ] do echo "Enter option: " read option echo "You entered $option. Is this correct? (y/n)" read verify done

?

Thank You !!!! Happy Learning & Happy Coding :-) Don't forgot to checkout Online Linux Terminal