Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.

Slides:



Advertisements
Similar presentations
CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
Advertisements

Introduction to UNIX CSE 2031 Fall May 2015.
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
CHAPTER 2 THE UNIX SHELLS by U ğ ur Halıcı. layers in a unix system 1 Users Standard utility programs (shell, editors, compilers, etc.) Standard utility.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
More about Shells1-1 More about Shell  Shells (sh, csh, ksh) are m Command interpreters Process the commands you enter m High-level programming languages.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
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.
Linux+ Guide to Linux Certification, Second Edition
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
CS 497C – Introduction to UNIX Lecture 4: Understanding the UNIX Command Chin-Chih Chang
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
UNIX Filters.
Shell Script Examples.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
Introduction to Shell Script 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.
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.
Shells. A program that is an interface between a user at a terminal and the computers resouces ▫The terminal may be real or an emulator The shell is.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Linux+ Guide to Linux Certification, Third Edition
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
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.
OPERATING SYSTEMS DESIGN UNIX BASICS & SHELL SCRIPTING.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux+ Guide to Linux Certification, Third Edition
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
CS465 - UNIX The Bourne Shell.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
UNIX An Introduction. Brief History UNIX UNIX Created at Bell Labs, 1969 Created at Bell Labs, 1969 BSD during mid 70s BSD during mid 70s AT&T began offering.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
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.
Linux Commands C151 Multi-User Operating Systems.
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.
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.
Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Second Edition
Lesson 6-Using Utilities to Accomplish Complex Tasks.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Linux Administration Working with the BASH Shell.
Agenda Customizing a Unix/Linux account Environment Introduction to Start-up Files (.bash_profile,.bashrc,.profile,.kshrc) Safe Methods for Changing Start-up.
Lesson 5-Exploring Utilities
Introduction to Shells
Prepared by: Eng. Maryam Adel Abdel-Hady
The UNIX Shell Learning Objectives:
Shell Script Assignment 1.
Sarah Diesburg Operating Systems CS 3430
Linux Shell Script Programming
Chapter 3 The UNIX Shells
CSC 4630 Meeting 4 January 29, 2007.
Presentation transcript:

Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental

Brief Reviewing of Shells Function of a shell: 1. Command Execution 2. Filename Substitution 3. I/O Redirection 4. Pipes 5. Environment Control 6. Background Processing 7. Shell Script

Shell Vatiables shell acts as a command interpreter. In order for shell to serve all your requests (executing commands, manipulating files,etc.), It needs to have certain information and to keep track of that information (such as: your home dir, terminal type, and prompt sign). This information is stored in shell variables. 1. Local variables---user defined 2. Environmental variables—standard variables

Displaying and Removing Variables: set and unset commands set to displaying the variables (both local and environmental) unset to remove a variable (you have to give a specific name for the variable) Rules have to be followed: 1. A shell variable name must begin with a letter and not a digit. 2. There are no spaces on either side of the equal sign.

Understanding the Standard Variables 1. They are mainly set by the system administrator. 2. You can change them just like you change the local variables. However, the changes are temporary and apply to only the current session. The next time you log in, If you want the changes to be permanent, place them in a file called.profile.

IFS ---Internal Field Separator Example: ls –l is a familiar command. What will happen if you forgot the space? What will happen if we do the following: echo $IFS save=$IFS will change the invisible space sign. *** This may not work on all Unix (Linux) Systems.***

MAILCHECK VARIABLE echo $MAILCHECK MAILCHECK=600 (every 10 minutes)

PATH Variable The PATH variable is set to the directory names that the shell searches for the location of commands (programs) in directory structure. Example: PATH=:/bin:/usr/bin 1. Separate dirs with : 2. When the first char in the PATH is :, the shell interprets it as.: (dot, colon)

Something Special about bin UNIX usually stores the executable files in the bin directory You can modify it such as : PATH=:/bin:/usr/bin:$HOME/mybin will add mybin (suppose you have stored all your exe files in mybin under HOME) It to your PATH variable.

PS1---Not IBM System 1 echo $PS1 echo $PS2 PS1=HERE: PS2=“To continue, hit ENTER key:”

More Metacharacters 1. Executing the commands: Using Single Back Quotation Marks `command` $echo The date and time is : `date’ $echo “List of filenames in your current directory:\n” `ls –C` > LIST 2. Sequencing the commands: semicolon ; $date; pwd; ls –C pwd—display the absolute pathname of your working directory. Will run one after another from left-to-right

Grouping the Commands: ( ) $( ls –C; date; pwd ) > outfile enter $cat outfile enter $( scriptName; date) > outfile2 Enter

Background Processing: “ & “ 1. Type a command followed by an “&” will put that command into the background processing. The purpose? Fully utilize multi-tasking For some program take long time to finish, one don’t have to wait. One can type and run another immediately.

Examples 1. $sort data > sorted & Process ID is displayed $ date i.e., one can type and run another command without waiting. You can specify more than one background command on a single command line. Date & pwd & ls –C & Enter

Terminating (kill) a process kill PID To be able to see the PID, type ps Enter

Chaining the Commands: “ | “ “ | “ is called pipe metacharacter. Format: command A | command B Example: $echo “Number of the logged in users:” `who | wc –l` > outfileName Enter

Options for ps: -a and -f -a --- Display the status of all the active processes, not just the user’s. -f --- Display a full list of information, including the full command line.

Keep On running: nohup When you log out, your background process will be terminated as well. 1. nohup can prevent this to happen. 2. The process, however, will not have any thing to do with any terminal. 3. When job (background process) is done, the redirected output (if any) will be saved in a file called “nohup.out”

Example $ nohup (sleep 120; echo “job done”) & ** This command may work differently on different systems.

Splitting the Output: the “tee” Aim: look at the output on the screen and save to a file at the same time. Example: $ ls –C | tee dir.list $ cat dir.list Enter

Options for “tee” -a -i tee –a ---Appends output to a file without overwriting an existing file. tee –i --- Ignores interrupts; does not respond to the interrupt signal.

File Searching: grep command grep (Global Regular Expression Print) grep is used to search for a specified pattern in a file or list of files. The pattern used by grep is called regular expression. Example: grep “bubble” bubble.c In cs315 directory Enter

grep Options -c --- Display only count of the matching lines in each file that contain the match. -i --- Ignores the distinction between lowercase and uppercase letters in the search pattern. -l --- Display the names of the files with one or more matching lines, not the lines themselves. -n --- Display a line number before each line. -v --- Display only those lines that do not match the pattern.

Unix Process Management Review: 1. Process---the execution of a program is called a process: you called it a program, but when your program is loaded into the memory for execution Unix calls it a process. 2. Unix maintains a process table for each process in the system and the table contains:

Process number Process status(ready/waiting) Event number that the process is waiting for System data area address

Sorting Text Files: The sort command Let look at an example first: We have a file named junk and it has the following contents: This is line one This is line two this is a line starting with a space character 4: this is a line starting with a number 11: this is another line starting with a number End of junk

From this example we can see: 1. ASCII values for nonalphanumeric characters (space, dash, backslash, etc.) are less than those for alphanumeric characters. 2. Uppercase letters are sorted before lowercase letters. 3. Numbers are sorted by first digit.

Options for sort command -b Ignore leading blank -d Use the dictionary order for sorting, ignore punctuation and control characters. -f ignore the distinction between lowercase and uppercase letters. -n Numbers are sorted by their arithmetic values. -o Store the output in the specified file. -r Reverse the order of the sort, from ascending to descending order. Examples: plist & plist2 in cs315 dir

STARTUP FILES System profile is stored in /etc/profile cat /etc/profile (Home dir) Enter Will display the content of profile 1.Usually, the system profile file is complex and incorporates some administration commands and requires some programming. 2. You can look at your profile file by the above example. Normally, it is a read-only file.

Process Table 1. Process number. 2. Process status (ready/waiting) 3. Event number that the process is waiting for 4. System data area address fork, parent and child in shells