Introduction to Unix (CA263) Quotes By Tariq Ibn Aziz.

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
COMP234 Perl Printing Special Quotes File Handling.
7 Searching and Regular Expressions (Regex) Mauro Jaskelioff.
Chapter 6 Dealing with quotes. Dealing with Quotes and slashes grep Susan phonebook grep Susan Goldberg phonebook  results in an error  grep ‘Susan.
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
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.
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Introduction to Perl Learning Objectives: 1. To introduce the features provided by Perl 2. To learn the basic Syntax & simple Input/Output control in Perl.
CS 497C – Introduction to UNIX Lecture 20: - The Shell Chin-Chih Chang
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction.
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.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
QUOTATION This chapter teaches you about a unique feature of the shell programming language: the way it interprets quote characters. Basically, the shell.
Grep grep allows you to search one or more files for particular character patterns. The general format of this command is grep pattern files Every line.
Shell Script Examples.
Shell Scripting Awk (part1) Awk Programming Language standard unix language that is geared for text processing and creating formatted reports but it.
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.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Input, Output, and Processing
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
EMT 2390L Lecture 8 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Writing Shell Scripts ─ part 3 CSE 2031 Fall October 2015.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Scripting Languages Course 2 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
CS465 - UNIX The Bourne Shell.
Workbook 6 – Part 2 The Bash Shell
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
Introduction to Unix (CA263) File Processing (continued) By Tariq Ibn Aziz.
Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.
Introduction to Unix (CA263) Passing Arguments By Tariq Ibn Aziz Dammam Community College.
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.
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
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.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
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.
Compunet Corporation Introduction to Unix (CA263) Round and Round By Tariq Ibn Aziz Dammam Community College.
© Prepared By: Razif Razali 1 TMK 265: UNIX SYSTEM CHAPTER FOUR – QUOTING IN DETAIL.
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?)
Introduction to UNIX (part 2) CSE 2031 Fall March 2016.
© Prepared By: Razif Razali 1 TMK 265: UNIX SYSTEM CHAPTER 8: USER INPUT.
Chapter 16 Advanced Bourne Shell Programming. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Objectives To discuss numeric data processing.
Shell scripts – part 1 Cs 302. Shell scripts  What is Shell Script? “Shell Script is series of command written in plain text file. “  Why to Write Shell.
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
Shell Scripting March 1st, 2004 Class Meeting 7.
Chapter 13 - The Preprocessor
Lecture 9 Shell Programming – Command substitution
Intro to PHP & Variables
Introduction to UNIX (part 2)
Introduction to Perl Learning Objectives:
Introduction to UNIX (part 2)
Introduction to Bash Programming, part 3
Introduction to Unix (CA263) Passing Arguments
Presentation transcript:

Introduction to Unix (CA263) Quotes By Tariq Ibn Aziz

Objectives In this lecture you will learn about one of the most unique feature of the shell programming: –The single quote character ‘ –The double quote character “ –The backslash character \ –The back quote character `

The Single Quote This must occur in pair. There are several reasons to use single quote in the shell

Character Separated by Space To keep characters together separated by space $ cat phonebook Alice Chebba Bob Swingle Liz Stachiw Susan Goldberg Susan Topple Tony Iannino $

Example $ grep Susan phonebook Susan Goldberg Susan Topple $ $ grep Susan Goldberg phonebook grep: can’t open Goldberg $ $ grep 'Susan Goldberg' phonebook Susan Goldberg $

Shell preserve spaces between quotes No matter how many space characters are enclosed between quotes, they are preserved by the shell. Shell removes the extra space characters from line and passes echo four argument one two three four $ echo one two three four one two three four $ space characters are preserved in the following example $ echo 'one two three four' one two three four $

Special characters inside the single quotes All special inside the single quotes are ignored by the shell if they appear inside single quote $ file=/usr/steve/bin/prog1 $ echo $file /usr/steve/bin/prog1 $ echo '$file' $file

Special characters inside the single quotes $ echo * address nu names phonebook stats $ echo '*' * $ echo ' | ; ( ) { } >> " `&' | ; ( ) { } >> " `& $ echo 'How are you today, > John' How are you today, John $

Special characters inside the single quotes $ message='I must say, this sure is fun' $ echo $message I must say, this sure is fun $ text='* means all files' $ echo $text address nu names phonebook stats means all files * was replaced by the names of all file

The Double Quotes Double quotes work similarly to single quotes, except they are not quite restrictive. –Single quote tells the shell to ignore all enclosed characters. –Double quote says to ignore most. In particular three characters are not ignored inside double quotes: Dollar signs Back quotes Backslash

Example Double Quote[1] $ x=* $ echo $* address nu names phonebook stats $ echo '$x' $x $ echo "$x" * $

Example Double Quote[2] $ address="11 Driscoll Dr > Brampton, ON, L6Y 3J2" $ echo $address 11 Driscoll Dr Brampton, ON, L6Y 3J2 $ $ echo "$address" 11 Driscoll Dr Brampton, ON, L6Y 3J2 The new line character is depicted by the characters \n

Example Double Quote[3] $ x="‘Hello,’ he said" $ echo $x ‘Hello,’ he said $ $ article=‘" My Name is," Tariq’ $ echo $article " My Name is," Tariq

The Backslash Basically, the backslash is equivalent to placing single quotes around a single character, with a few minor exceptions. The general format is: –\c –Where c is the character you want to quote.

Example[1] $ echo > Syntax error: ‘newline or ;’ unexected Shell saw > and thought you wanted to redirect echo’s output to a file. $ echo \> > $

Example[2] $ x=* $ echo \$x $x In this case backslash ignore the $ that followed the backslash and as a result variable substitution was not performed. $ echo \\ \ $ echo '\' \

Using Backslash for Continuing Lines Single quote tells shell to ignore newline $ lines=one’ > 'two $ echo "$lines" one two Try this with \ instead. $ lines=one\ > two $ echo "$lines" onetwo The shell treat \ as a line continuation.

The Backslash inside Double Quotes If backslash precedes any character inside double quotes, then backslash is ignored by the shell and passed on to the program: $ echo "\$x" $x $ echo "\ is the backslash character" \ is the backslash character $ x=5 $ echo "The value of x is \"$x\"" The value of x is "5"

Lab Exercise Display the following line: >> display the value $x, which is $x $ x=5 >> display the value $x, which is 5

The Back Quote The back quote tells the shell to execute the enclosed command. $ echo The date and time is: `date` The date and time is: Tue Jul 16 09:14:22 EDT 1985 $ echo current dir is: `pwd` current dir is: /usr/steve/bin

The Back Quote The back quote tells the shell to execute the enclosed command. $ cat nu echo There are `who|wc –l` users logged on $ nu There are 13 users logged on

The Back Quote The Single quotes protect everything. $ echo ‘`who|wc –l` tell how many users’ `who|wc –l` tell how many users The Double quotes interpret back quotes. $ echo "You have `ls|wc –l` files" You have 7 files

The Back Quote Execute date and store the output in now $ now=`date` $ echo $now Tue Jul 16 09:14:22 EDT 1985 $

The Back Quote $ filelist=`ls` $ echo $filelist address nu names phonebook stats $ echo "$filelist" address nu names phonebook stats

The Back Quote To store a content of a file into the variable, you can use cat: $ namelist=`cat names` $ echo "$names" address nu names phonebook stats

Change the Variable Value[1] The back quote mechanism can be used to change the value of a variable: $ name="Tariq Aziz" $ name=` echo $names | tr '[a-z]' '[A-Z]'` $ echo $name TARIQ AZIZ

Change the Variable Value[2] The back quote mechanism can be used to change the value of a variable: $ file name=/usr/steve/memos $ firstchar=` echo $filenames | cut –c1` $ echo $firstchar /

Change the Variable Value[3] The back quote mechanism can be used to change the value of a variable: $ file =exec.o $ lastchar=` echo $filenames|sed 's/.*\(.\)$/\1/'` $ echo $lastchar o

Arithmetic on Shell Variable The shell has no concept of performing arithmetic on values stored inside variables. $ i=1 $ i=$i+1 $ echo $i 1+1 $

Arithmetic on Shell Variable The UNIX program called expr evaluate an expression given to it on the command line. $ expr $ expr $ Each operator and operand must be separated by space.

Arithmetic on Shell Variable The usual arithmetic operators are recognized by expr: + for addition, - for subtraction, / for division, * for multiplication, and % for modulus. $ expr / 2 20 Each operator and operand must be separated by space. $ expr $

Arithmetic on Shell Variable $ expr 17 * 6 expr: syntax error What happened here? The shell saw * and substituted the names of all files in your directory. $ expr "17 * 6" 17 * 6

Arithmetic on Shell Variable $ expr 17 \* Example $ i=1 $ expr $i Example $ i=1 $ i=`expr $i + 1` $ echo $i 2