Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.

Slides:



Advertisements
Similar presentations
Shell Script Assignment 1.
Advertisements

การใช้ระบบปฏิบัติการ UNIX พื้นฐาน บทที่ 4 File Manipulation วิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ ม. สงขลานครินทร์ เวอร์ชั่น 1 วันที่
7 Searching and Regular Expressions (Regex) Mauro Jaskelioff.
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Linux+ Guide to Linux Certification, Second Edition
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.
CS 497C – Introduction to UNIX Lecture 20: - The Shell Chin-Chih Chang
The UNIX Shells 1. What is a Unix shell? 2. A few common shells in the Unix & Linux. A. Bourne shell B. Korn shell C. C shell D. Bash-the default shell.
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.
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.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Shell Programming The activities of.
Introduction to Shell Script Programming
Writing Shell Scripts ─ part 1 CSE 2031 Fall September 2015.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell The agency that.
Chapter 5 Bourne Shells Scripts By C. Shing ITEC Dept Radford University.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
An Introduction to Unix Shell Scripting
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 8 Shell.
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.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Essential Shell Programming by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
Linux+ Guide to Linux Certification, Third Edition
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.
Workbook 6 – Part 2 The Bash Shell
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
I/O Redirection and Regular Expressions February 9 th, 2004 Class Meeting 4.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: whereis, which, whoami, finger, passwd, cal, date Working with Files: cat, more, less.
Ch 91 Pipes, Filters and Redirection. Ch 92 Overview Will use redirection to redirect standard input and standard output.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
CIT 140: Introduction to ITSlide #1 CIT 140: Introduction to IT Shell Programming.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
Chapter Six Introduction to Shell Script Programming.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
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.
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.
Chapter 5: The Shell The Man in the Middle. In this chapter … The command line Input, output, and redirection Process management Wildcards and expansion.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Linux+ Guide to Linux Certification, Second Edition
Agenda The Bourne Shell – Part I Redirection ( >, >>,
1 © 2012 John Urrutia. All rights reserved. Chapter 09 The TC Shell.
1 Week 8 Creating Simple Shell Scripts. 2 Chapter Objectives  In this chapter, you will :  Learn how to create Shell Scripts  Commenting / Making Portable.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Chapter 15 Introductory Bourne Shell Programming.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Shell Features CSCI N321 – System and Network Administration
Agenda Korn Shell Functions Korn Shell Variables
Shell Scripting March 1st, 2004 Class Meeting 7.
Shell Script Assignment 1.
John Carelli, Instructor Kutztown University
Linux Shell Script Programming
Presentation transcript:

Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional Parameters)

Special Characters A special character is used to give special meaning to a file or string when used with a UNIX command or when executing shell scripts. For example redirection (>, >>, <) Special characters are used for: Wildcard searches Redirecting standard output Displaying variable contents

Special Characters You should avoid using special symbols when creating files. You should also be aware that special symbols when used in shell scripts can cause problems (shell may interpret them differently than user) Examples: > < * ? ‘ “ \ $ ; / `

Quoting text When creating shell scripts, you may want to make reference to text that includes a special character. To make the shell “ignore” the meaning of the special character you use quotes. Types of Quotes: Single Quotation marks:echo ‘*’ Double Quotation marks:echo “*” Backslash:echo \* Note: A backslash must appear for every occurrence of a special symbol – we will discuss more about quoting text later in this course…

Ambiguous File References (Wildcard Searches) You may need to access or process a file, but forget what the exact spelling (syntax) of the filename. You may also want to run a shell script that accesses many files that share a similar characteristic (eg all files with extension “txt”). Files that match a pattern (as opposed to being referenced by an exact filename) is called an ambiguous file reference

The * character This wildcard character is used to represent any character. It is useful when searching for file names sharing common characteristics. For Example : ls file*(list all files beginning with “file”) ls –a.* (list all hidden files)

The ? character The wildcard character ? will match only a single character. ls file? (list all files with only 1 character after “file”) ls file?? (list all files with only 2 characters after “file”) ls ??45? (list all files containing 5 characters that contain a 4 in 3 rd position and a 5 in the 4 th position)

Character Class [ ] Used to match a particular group or “class” of a single character. Similar to using “?” but the user can determine what “?” is allowed or not allowed to represent. Examples ls file[abc].txt displays filea.txt, fileb.txt, filec.txt ls file[1-9].txt displays a range file1.txt to file9.txt cat file[!abd].doc displays all other files than filea.doc, fileb.doc or filed.doc

Variable Names ($) The shell has the ability for users to assign values to a variable. There are basically two general categories of variables in UNIX: Shell Variables (Assigned by the Shell) User-Created Variables (Assigned by the user)

Shell Variables There are two categories of shell variables: Keyword Variables Variables that have been assigned an easy to remember word that are commonly used Examples include PATH, VISUAL, PS1, PS2, etc… Read-only Shell Variables (Positional Parameters) Variables that are assigned by a command (set) as opposed to assigning by using the equal sign (=) Examples include $1, $2, $3, … $9

User-Created Variables A user-created variable must begin with a letter. You must not include white-space on either side of the equals sign For example: cat >test.file name=Murray

User-Created Variables In order to access or display the value of the variable, a dollar sign $ must appear before the variable name - otherwise, it would be interpreted as text. For Example: cat > test2.file name=Murray echo $name

User-Created Variables You can use single or double quotes to assign an entire string of text For Example: name=‘Murray Saul’ name=“Murray Saul” Note: Single quotes (‘ ’) and backslash (\) will turn-off meaning of special characters including the variable name eg. echo ‘$name’ (Double quotes will allow variable to display value!!)

User-Created Variables To remove a previously stored variable, assign a “null” value to the variable or use unset command Example: name= unset name

Reading & Storing Input From the User The read command is used to pause and prompt the user to enter a line of text. Example: echo “Enter your full name \c” read fullname echo $fullname \c within quotes prompts user for data on same line as message...

Read-Only Shell Variables (Positional Parameters) Read-Only shell variables have the feature to store commands and relating arguments as well as command output. You can use the set command to assign values to these read-only shell variables. You can also create shell scripts and have arguments after script name automatically stored in read-only shell variables

Read-Only Shell Variables Read only variables range from $0 to $9 $0 is name of command used to call script $1 to $9 are first nine positional parameters, or command line arguments Read-Only Shell Variables need to be set For Example set name1 name2 name3 $0 = set $1 = name1 $2 = name2 $3 = name3

Examples of Read-Only Variables Try to determine output from the following commands: set date echo $0 $1 $2 set whoami echo $1 $2 set name1 name2 name3 echo $* set `date` echo $0 $1 $2 $3 $* matches all variables Can use Read-Only Variables to read output from executed command (must use ` symbol around command)

Exporting a Variable As mentioned in a previous lesson, UNIX runs a series of operations or “processes”. Processes can start other operations or “child processes” Unfortunately, variables are usually only stored in the current or “local” process. Therefore, the export command is used to transfer or “export” the variable to the child processes (if they are required)

Exporting a Variable Usage: export variable_name During the weekend, check your.profile to see if there are any variables exported - we will discuss this next week…