Compunet Corporation Introduction to Unix (CA263) More on Parameters By Tariq Ibn Aziz Dammam Community College.

Slides:



Advertisements
Similar presentations
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Advertisements

Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
CS 497C – Introduction to UNIX Lecture 32: - Shell Programming Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
CIT 140: Introduction to ITSlide #1 CIT 140: Introduction to IT Advanced Shell Programming.
Introduction to Unix (CA263) Decisions, Decisions By Tariq Ibn Aziz Dammam Community College.
More Shell Programming Learning Objectives: 1. To learn the usage of environment (shell) variables in shell programming 2. To understand the handling of.
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Shell Script Examples.
Shell Control Structures CSE 2031 Fall August 2015.
Lecture 3  Shell Variables  Shell Command History  Job / Process Control  Directory Control.
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.
Chapter Nine Advanced Shell Scripting1 System Programming Advanced Shell Scripting.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Parameter substitution ParameterMeaning $parameter or ${parameter} Substitute the value of parameter ${parameter:- value} Substitute the value of parameter.
1 Shell Programming – Extra Slides. 2 Counting the number of lines in a file #!/bin/sh #countLines1 filename=$1#Should check if arguments are given count=0.
An Introduction to Unix Shell Scripting
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
The if construct The general format of the if command is: Every command has exit status If the exit status is zero, then the commands that follow between.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
Writing Shell Scripts ─ part 3 CSE 2031 Fall October 2015.
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.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
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.
CS465 - UNIX The Bourne Shell.
LINUX programming 1. INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Introduction to Unix (CA263) Passing Arguments By Tariq Ibn Aziz Dammam Community College.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
CIT 140: Introduction to ITSlide #1 CIT 140: Introduction to IT Shell Programming.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
Shell Programming Features “Full” programming language “Full” programming language Conditional statements Conditional statements Arithmetic, String, File,
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Introduction to Unix (CA263) Quotes By Tariq Ibn Aziz.
Compunet Corporation Introduction to Unix (CA263) Your Environment By Tariq Ibn Aziz Dammam Community College.
Environment After log in into the system, a copy of the shell is given to the user Shell maintains an environment which is distinct from one user to another.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.
Introduction to Unix (CA263) Command File By Tariq Ibn Aziz.
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.
Compunet Corporation Introduction to Unix (CA263) Round and Round By Tariq Ibn Aziz Dammam Community College.
Compunet Corporation Introduction to Unix (CA263) Reading Data By Tariq Ibn Aziz Dammam Community College.
Various 2. readonly readonly x=4 x=44 #this will give an error (like what in java?)
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Chapter 15 Introductory Bourne Shell Programming.
1 UNIX Operating Systems II Part 2: Shell Scripting Instructor: Stan Isaacs.
Shell Control Structures CSE 2031 Fall June 2016.
Chapters 13 and 14 in Quigley's "UNIX Shells by Example"
Lecture 7 Introduction to Shell Programming
Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
CSC 352– Unix Programming, Spring 2016, Final Exam Guide
How to link a test to a launcher (in this case a shell launcher)
Lecture 9 Shell Programming – Command substitution
Shell Programming (ch 10)
Unix Scripting Session 4 March 27, 2008.
The Linux Operating System
Shell Script Assignment 1.
Writing Shell Scripts ─ part 3
Agenda Functions: What are functions? / Purpose of Functions
Linux Shell Script Programming
Introduction to Bash Programming, part 3
Introduction to Unix (CA263) Passing Arguments
Presentation transcript:

Compunet Corporation Introduction to Unix (CA263) More on Parameters By Tariq Ibn Aziz Dammam Community College

Compunet Corporation Objectives In this lecture you will learn –The $0 Variable –The set Command –The IFS Variable –The readonly Command –The unset Command

Compunet Corporation The $0 Variable The shell automatically store the name of the program inside the special variable $0. $ cat lu # # Look someone up in the phone book # if [ "$#" –ne 1 ] then echo "Incorrect number of arguments" echo "Usage: $0 name" exit 1 fi grep "$1" $PHONEBOOK

Compunet Corporation The set Command The shell set command is a dual purpose command. It’s used both to set various shell options as well as to reassign the positional parameter $1, $2,... $ x=* $ set –x $ echo $x +echo add greetings lu rem rolo add greetings lu rem rolo To turn off trace option. $ set +x $ echo $x add greetings lu rem rolo

Compunet Corporation The set Command You can trace a subshell execution either by running the shell with the –x option followed by the name of the program to be executed. $ sh –x rolo

Compunet Corporation Set with No Arguments If you don’t give any argument to set, you will get alphabetized list of all of the variables that exist in your environment. $ set CDPATH=:/usr/steve:/usr/spool EDITOR=/bin/vi HOME=/usr/steve IFS= PATH PS1=$ PS2=> PWD=/usr/steve/misc SHELL=/bin/sh TERM=hp2621 x=*

Compunet Corporation Using set to Reassign Positional Parameters $ set a b c assigns a to $1, b to $2, and c to $3. $# also gets set to 3. $ set one two three four $ echo $1:$2:$3:$4 one:two:three:four $ echo $# 4 $ echo $* one two three four

Compunet Corporation set Example $ for arg; do wcho $arg; done one two three four

Compunet Corporation set Example $ cat words read line set $line echo $# $ words Here’s a line for you to count 7 $

Compunet Corporation The IFS Variable There is a special shell variable called IFS, which stand for Internal Field Seperator. The shell uses this variable when parsing input from the read command, output from command substitution, and when performing variable substitution. $ echo "$IFS"

Compunet Corporation The IFS Example $ IFS=: $ read x y z 123:345:678 $ echo $x 123 $ echo $z 678 $ list="one:two:three“ $ for x in $list > do > echo $x > done one two three $ var=a:b:c $ echo "$var“ a:b:c

Compunet Corporation Changing IFS with set $ line=“Micro corp:Box 174: Dammam, “ $ IFS=: $ set $line $ echo $# 3 $ for field; do echo $field; done Micro Corp Box 174 Dammam, $

Compunet Corporation The readonly Command The readonly command is used to specify variables whose values cannot be subsequently changed. readonly PATH HOME makes the PATH and HOME variable readonly. After this assigning a value to these variable will cause shell to issue an error message.

Compunet Corporation The readonly Command To get a list of your readonly variables, type readonly without any argument. $readonly PATH HOME

Compunet Corporation The unset Command Sometime you may wish to remove the definition of a variable from your environment. $x=100 $ echo $x 100 $ unset x $ echo $x $ You can’t unset a readonly variable. Furthermore, the variable IFS, MAIL-CHECK, PATH, PS1, and PS2 cannot be unset.