Shell Programming Oleh: Idris Winarno. Topik Hello world!!! Variables Functions Conditionals Loops Function.

Slides:



Advertisements
Similar presentations
Iteration While / until/ for loop. Iteration: while/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initalise.
Advertisements

CSE4251 The Unix Programming Environment
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.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Linux Shell Script. Shell script The first line is used to specify shell program #!/bin/sh Variables variable=“text” variable=0 variable=`program arguments`
(define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) GE f: P1 para:x body:(if … )
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.
23-Jun-15Advanced Programming Spring 2002 bash Henning Schulzrinne Department of Computer Science Columbia University.
Bash, part 2 Prof. Chris GauthierDickey COMP Unix Tools.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
 What is a shell? A shell script?  Introduction to bash  Running Commands  Applied Shell Programming.
Introduction to Linux and Shell Scripting Jacob Chan.
Shell Script Examples.
Lab 8 Shell Script Reference:
LINUX Shell Scripting Advanced Issues
1.1 Command Substitution The backquote “`” is different from the single quote “´”. It is used for command substitution: `command`  $ LIST=`ls` $ echo.
Scripting CBIS BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it in.sh file1.sh Step 2 – Using CHMOD make the bash file.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Linux Shell Programming Tutorial 3 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi.
CMPSC 60: Week 6 Discussion Originally Created By: Jason Wither Updated and Modified By: Ryan Dixon University of California Santa Barbara.
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.
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
BASH Scripting A beginners guide to Bourne Again SHell scripting.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
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.
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
Lecture 2: Advanced UNIX, shell scripts (ol)‏ Programming Tools And Environments.
Shells. Variables MESSAGE="HELLO WORLD" echo $MESSAGE MESSAGE="HELLO WORLD $LOGNAME" echo $MESSAGE MESSAGE="HELLO WORLD $USER" echo $MESSAGE.
Writing Scripts Hadi Otrok COEN 346.
©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.
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.
Shell Script2 Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Shell Programming Features “Full” programming language “Full” programming language Conditional statements Conditional statements Arithmetic, String, File,
1 Unix/Linux commands and shell programming-Part 2 (Dr. Mohamed El Bachir Menai)
Lab 8 Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Lab 8 Overview Apache Web Server. SCRIPTS Linux Tricks.
Shell script – part 2 CS 302. Special shell variable $0.. $9  Positional parameters or command line arguments  For example, a script myscript take 2.
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]
Chapter 5 The Bourne Shell Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Notes by Michael Weeks.
Various 2. readonly readonly x=4 x=44 #this will give an error (like what in java?)
Various 3. Noclobber 1 echo hello > output.txt But what if output is an inportant file and you do not want to make a mistake!!! set –o noclobber Now you.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
1 UNIX Operating Systems II Part 2: Shell Scripting Instructor: Stan Isaacs.
Linux Essentials Chapter 12: Creating Scripts. Chapter 12 Outline Beginning a shell script Using commands Using arguments Using variables Using conditional.
Bash Shell Scripting 10 Second Guide.
Linux Shell Programming
CSC 352– Unix Programming, Spring 2016, Final Exam Guide
Chapter 9 Shell Programming
CSC 352– Unix Programming, Fall 2012
Part 1: Basic Commands/Utilities
Lecture 9 Shell Programming – Command substitution
Shell Programming (ch 10)
Pepper (Help from Dr. Robert Siegfried)
LING 408/508: Computational Techniques for Linguists
UNIX Reference Sheets CSE 2031 Fall 2010.
Linux Shell Script Programming
Presented by, Mr. Satish Pise
Chapter 5 The Bourne Shell
CSC 352– Unix Programming, Fall, 2011
Introduction to Bash Programming, part 3
Bash Scripting CS 580U - Fall 2018.
Basic shell scripting CS 2204 Class meeting 7
Presentation transcript:

Shell Programming Oleh: Idris Winarno

Topik Hello world!!! Variables Functions Conditionals Loops Function

Percobaan 1 # vi coba1.sh #!/bin/bash echo “Hello world” #chmod u+x./coba1.sh./coba1.sh

Percobaan 2 # vi coba2.sh #!/bin/bash pwd ls -l date # chmod u+x./coba2.sh./coba2.sh Bandingkan dengan: # pwd; ls -l; date

Percobaan 3 # vi coba3.sh # !/bin/bash var1=“Hello world” var2=`ls` echo $var1 echo $var2 # chmod u+x./coba3.sh #./coba3.sh

Percobaan 4 vi coba4.sh #!/bin/bash HELLO=Hello function hello { local HELLO=World echo $HELLO } echo $HELLO hello echo $HELLO # chmod u+x./coba4.sh #./coba4.sh

Percobaan 5 # vi coba5.sh #!/bin/bash if [ "foo" = "foo" ]; then echo expression evaluated as true fi # chmod u+x./coba5.sh./coba5.sh

Percobaan 6 # vi coba6.sh #!/bin/bash T1="foo" T2="bar" if [ "$T1" = "$T2" ]; then echo expression evaluated as true else echo expression evaluated as false fi # chmod u+x./coba6.sh./coba6.sh

Percobaan 7 vi coba7.sh #!/bin/bash for i in $( ls ); do echo item: $i done # chmod u+x./coba7.sh./coba7.sh

Percobaan 8 vi coba8.sh #!/bin/bash COUNTER=0 while [ $COUNTER -lt 10 ]; do echo The counter is $COUNTER let COUNTER=COUNTER+1 done # chmod u+x./coba8.sh./coba8.sh

Percobaan 9 # vi coba9.sh #!/bin/bash function quit { exit } function hello { echo Hello! } hello quit echo foo # chmod u+x./coba9.sh #./coba9

Percobaan 10 # vi coba10.sh #!/bin/bash function quit { exit } function e { echo $1 } e Hello e World quit echo foo # chmod u+x./coba10.sh./coba10.sh