Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.

Slides:



Advertisements
Similar presentations
June 1, 1999Foreground/Background Processing1 Introduction to UNIX H. Foreground/Background Processing.
Advertisements

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.
Processes and Job Control. Foreground and Background (1)  Unix is a multi-tasking operating system –some of these tasks are being done by other users.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
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.
Shells and Processes Bryce Boe 2012/08/08 CS32, Summer 2012 B.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
CS 497C – Introduction to UNIX Lecture 26: - The Process 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.
The UNIX Shell Software Tools. Slide 2 Basic Shell Syntax command [-[options]] [arg] [arg] … l The name of the command is first l Options are normally.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
2000 Copyrigths Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 3.
23-Jun-15Advanced Programming Spring 2002 bash Henning Schulzrinne Department of Computer Science Columbia University.
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.
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.
Guide To UNIX Using Linux Third Edition
Shell Script Examples.
Lecture 3  Shell Variables  Shell Command History  Job / Process Control  Directory Control.
5 UNIX Processes. Introduction  Processes  How to list them  How to terminate them  Process priorities  Scheduling jobs  Signals.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
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
Chapter 5 Bourne Shells Scripts By C. Shing ITEC Dept Radford University.
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
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.
CS 6560 Operating System Design Lecture 3:Tour of GNU/Linux.
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
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
CS465 - UNIX The Bourne Shell.
Chapter 2: Linux & POSIX “She sells bash shells by the C shore”
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Hands On UNIX II Dorcas Muthoni. Processes A running instance of a program is called a "process" Identified by a numeric process id (pid)‏  unique while.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
Customizing the Shell Environment. UNIX Shells Two characteristics of shells –Interactive: prompts ($) and waits for your response/requests –Noninteractive:
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Chapter 5: The Shell The Man in the Middle. In this chapter … The command line Input, output, and redirection Process management Wildcards and expansion.
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 9 Working.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Jozef Goetz, expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
1 © 2012 John Urrutia. All rights reserved. Chapter 09 The TC Shell.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
CS 350 Lecture 3 UNIX/Linux Shells by İlker Korkmaz and Kaya Oğuz.
Introduction to Shells
The UNIX Shell Learning Objectives:
System Programming and administration CS 308
Part 1: Basic Commands/Utilities
Shell Script Assignment 1.
Basic UNIX OLC Training.
Introduction to UNIX.
John Carelli, Instructor Kutztown University
The Linux Command Line Chapter 10
CSC 140: Introduction to IT
Shell Programming.
Linux Shell Script Programming
Chapter 5 Bourne Shells Scripts
Chapter 3 The UNIX Shells
Presentation transcript:

Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University

Objectives Understand different Unix shells and how to change Understand how to use wildcards Understand how to shell variables and how to set up Understand how to create sub-shells Understand common shell commands Understand the difference of using arithmetic expressions in all four shells

Unix Shells 4 Unix command shells: 1.Bourne (by Steve Bourne): provided in most Unix machines, use /bin/sh to create a sub-shell, good for batch processing, lack of aliases and command history, prompt $ 2.C (by Bill Joy): good for interactive work, use /bin/csh to create a sub-shell, has aliases and command history, prompt % 3.Korn (by David Korn): combine interactive features from C shell and programming features from Bourne shell, lack of directory stack manipulation and weak aliases, use /bin/ksh to create a sub-shell, prompt $ 4.Bash(Bourne Again by GNU): most freely available, conform to POSIX shell specification, use /bin/bash to create a sub-shell, prompt bash$ Note: use chsh to change to different login shell.

Linux Command Options There are 3 options are available for Linux commands: 1.Use – (Common used in Unix) 2.Use - - (POSIX form) 3.Use nothing (BSD form) Example: ls –l (common form) ls - - l (POSIX form) ls l (BSD form)

Shell Wildcard NameExplain *0 or more characters ?match any one character [...]match any one of the characters within [ ]

Shell Wildcard Examples: –ls * list all filenames –ls ? list filenames having one character

Shell Variables 1.Environment (or Global) variables: (upper case letter) copied automatically to sub-shell Built-in User-defined 2.Local Variables: used in individual shell only Built-in User-defined

Shell Variables – built-in Environment Built-in Environment Variables NameExplain $HOMEHome directory $PATHSearched path $MAILMailbox path $USERUsername $SHELLLogin shell $TERMTerminal type

Shell Variables – built-in Environment Examples: Check environment variables –env, an external command and runs in a child process –or echo $TERM

Shell Variables – set-up Environment Examples: Change environment variables –set TERM=vt100or –setenv TERM vt100

Shell Variables – built-in Local Built-in Local Variables NameExplain $$Shell PID $0, $1, …, $9 Shell command line parameters $*All shell command line parameters

Shell Variables – built-in Local Examples: Check Local variables –echo $variablename or –set a shell built-in command

Shell Variables – set-up Local Examples: Change Local variables –set variablename=value

Process Control - ps ps: check process status –Syntax: ps –option  Option:  e: list all currently running processes (A for Linux)  f: gives full listing (give ancestry for Linux)  l: gives long listing  u username: list processes for the user only

Process Control - ps Example: –ps –el list all process information with columns:  S: state  S: sleeping  O: running  R: on run queue  Z: zombie (parent didn’t wait for death of its child  T: stopped or suspended Note: A process is orphan if parent dies before its child

Process Control - ps Example: (Cont.)  UID  PID: process id  PPID: parent PID  PRI: priority  SZ: total pages in virtual memory  TIME: execution time  CMD: command

Process Control (Cont.) bg or &: sends foreground process to background Ctrl-z (or ctrl-]-z in DOS): stop process running jobs: shows all background processes id fg %id: sends background process id to foreground kill %id: terminate background process id kill -9 pid: terminate foreground process id Ctrl-c: terminate current running process

Process Control (Cont.) Note: for background process, no standard input is available, no way to see the standard output and standard error. You can either redirect output/error or let kernel to suspend the process right before standard output and standard error by setting as below: stty tostop

Process Control (Cont.) Example: use one Unix window –cat –Ctrl-z –Jobs –cat > file2 & –jobs –fg %1 –Ctrl-z –kill %1 (or kill %cat or kill %?file2) –jobs –tty find the terminal –fg

Process Control (Cont.) Example: (Cont.) use another one Unix window –ps –u username find the process id for the previous shell –kill -9 PID this will terminate the process: cat > file2

Create Sub-Shell 4 ways to create subshells: 1.group shell commands within ( ). Examples: pwd; (cd /; pwd); pwd The commands in ( ) are executed in a subshell. 2.invoke /bin/sh, /bin/csh, /bin/ksh, or /bin/bash 3.starts background processes. 4.starts a shell script

Common Shell Commands command substitution ` ` Examples: echo today is `date`

Common Shell Commands quoting(in pair): Rules: double quotes prevents wildcard replacement only. single quote prevents wildcard replacement, variable substitution and command substitution. only the outer quote works if quotes are nested

Common Shell Commands Examples: echo * The shell expands *. echo "*" The shell does not expands *. echo '*' The shell does not expands *. echo "the user is $USER and files are `ls *`" The shell expands $USER and *. echo 'the user is $USER and files are `ls *`' The shell does not expands either $USER or *.

Common Shell Commands sleep n1 The shell sleeps for n1 seconds. Examples: (sleep 5; echo subshell done)&; ps -f

Common Shell Commands wait [n] The shell suspends its processes until child PID n (background process) terminates. Examples: (sleep 10; echo done #1)&; (sleep 20; echo done #2)&; echo done #3; wait; echo done #4 the shell prints done #3 and wait until subshell prints done #1, them done #2. Then it prints done #4.

Common Shell Commands exit n The shell exits with return code n.

Common Shell Commands eval command It executes the output of the command as a regular shell command. Examples: eval `set echo x=2`; echo $x (Solaris) eval set echo x=2; echo $x (Linux)

Common Shell Commands exec command It executes the command and then terminates the shell. Examples: exec date

Common Shell Commands command1 && command2 command2 will be executed after the success of executing command1 Examples: gcc beep.c && a.out

Common Shell Commands command1 || echo error_message error_message will be printed after the failure of executing command1 Examples: gcc beep_syntaxerror.c || echo compilation error

Difference in Arithmetic Expression C ShellBourne Shell Korn Shell Bash Shell Start Up File.cshrc, then.login.profile.profile or.kshrc.bashrc or.bash_profile Arith metic Expre ssion set x=1 echo x ++ echo $x x=1 echo $x x=`expr $x + 1` echo $x let x=1 echo $x let x=x+1 echo $x declare -i x x=($x+1) echo $x x=($x+1) echo $x

Reference Misc. (for Linux other than Ubantu) killall –u uid: kills all other shell processes killall -9 tcsh: kills all tcsh shell processes Ch. 4