Lecture 3  Shell Variables  Shell Command History  Job / Process Control  Directory Control.

Slides:



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

Lecture 4 Shell environment III: - command alias & history; - job control; - editor (vim) CSE4251 The Unix Programming Environment 1.
Chapter 9: The TC Shell Everything you thought you knew is now wrong.
Introduction to Unix – CS 21 Lecture 10. Lecture Overview Midterm questions Jobs and processes description The foreground and background Controlling jobs.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
Chapter 13 Processes. What is a process? A process is a program in execution A process is created whenever an external command is executed Whenever the.
Understanding bash Prof. Chris GauthierDickey COMP 2400, Fall 2008.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
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.
Scripting Languages and C-Shell. What is a scripting language ? Script is a sequence of commands written as plain text and run by an interpreter (shell).
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
CTEC 1863 – Operating Systems Shell Scripting. CTEC F2 Overview How shell works Command line parameters –Shift command Variables –Including.
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.
Exam Revision. Exam Details Time 90 minutes (1hour 30 minutes). Six questions! How long per question? Five parts per question. How long for each part?
Chapter Nine Advanced Shell Scripting1 System Programming Advanced Shell Scripting.
An Introduction to Unix Shell Scripting
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface What is the directory tree Some UNIX commands.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
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.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
Lecture 4  C Shell Scripts(Chapter 10). Shell script/program  Shell script: a series of shell commands placed in an ASCII text file  Commands include.
LINUX System : Lecture 6 Shell Programming
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.
1 Homework / Exam HW7 is due next class Starting Glass chapter 4 and parts of 7 Exam 3 – Class 26 –Open Book / Open Notes –Up through End of K&R Chapter.
CS465 - UNIX The Bourne Shell.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
1 Unix Seminar #1 T.J. Borrelli Lecturer for CS and NSSA February 6th, 2009.
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.
Adv. UNIX:CShell/71 Advanced UNIX v Objectives of these slides: –introduce the C Shell –concentrate on features not in the Bourne Shell (but many.
Welcome to CS323 Operating System lab 1 TA: Nouf Al-Harbi NoufNaief.net.
Shell Programming Features “Full” programming language “Full” programming language Conditional statements Conditional statements Arithmetic, String, File,
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Linux Commands C151 Multi-User Operating Systems.
1 Unix/Linux commands and shell programming-Part 2 (Dr. Mohamed El Bachir Menai)
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.
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop VI Scheduling & Process Management Professional.
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.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
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.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
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.
Foreground and background processes
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Introduction to Shells
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Part 1: Basic Commands/Utilities
CSE 374 Programming Concepts & Tools
Shell Environments.
Basic UNIX OLC Training.
Sarah Diesburg Operating Systems CS 3430
The Linux Command Line Chapter 10
CSCI The UNIX System Shell History and Directory Stacks
Unix Talk #2 (sed).
Shell Programming.
Shells jbliao.
Shells.
Linux Shell Script Programming
Chapter 3 The UNIX Shells
Presentation transcript:

Lecture 3  Shell Variables  Shell Command History  Job / Process Control  Directory Control

Shell Variables  The shell keeps track of a set of parameter names and values, which determine the behavior of the shell. set new values for some variables to customize the shell. set new values for some variables to customize the shell. find out the value of some variables to help accomplish a task. find out the value of some variables to help accomplish a task.  C shell maintains two sets of variables: Shell Variables: only effective within this current shell. Shell Variables: only effective within this current shell. Environment Variables: automatically exported to other applications invoked Environment Variables: automatically exported to other applications invoked

Shell Variables Operations  Set the variables % set var = % set var = % setenv VAR % setenv VAR  Unset the variables % unset var % unsetenv VAR  Display the variables % set % setenv  Display the value of the variables % echo $var % echo $VAR

Predefined Shell Variables  $ argv: list of arguments passed to the current command  $ cwd: full pathname of current dir  $ history: number of commands saved in history  $ home: home dir (~)  $ path: list of pathnames to search for commands to execute  $ shell: name of shell in use (ex: /bin/csh)  $ status: exit status of last command

Variable Types  Strings and arrays  Arrays hold lists of strings % set array_name=(string1 string2…) % set array_name=(string1 string2…)  % set test1 = “Hello World”  % set test2 = (Hello World)  % set test3 = ($test1)  % set test3 = ($test3 My Name Is Scott)

Variables Expressions  Using variables expressions, we can extract other info. about the shell variables: $var or ${var}: value of variable var $var or ${var}: value of variable var $?var or ${?var}: 1- if var is set ; 0 – if var is not set $?var or ${?var}: 1- if var is set ; 0 – if var is not set $var[1] or ${var[1]}: first word in the value of var $var[1] or ${var[1]}: first word in the value of var ${var[-10]}: words 1-10 in var${var[-10]}: words 1-10 in var ${var[2-]}: words staring from word 2${var[2-]}: words staring from word 2 $var[*] or ${var[*]}: all words in the value of var $var[*] or ${var[*]}: all words in the value of var $0: name of the program being executed $0: name of the program being executed $<: read a line from stdin $<: read a line from stdin

C Shell Command History  C shell maintains a history of commands executed up to $history maximum Command substitution Command substitution Command history modifiers Command history modifiers Argument substitution Argument substitution  Current history can be examined by % history  Upon logout, up to $savehist most recent commands from the history are saved in ~/.history, s.t. these commands can be reloaded next time the shell is started

Command Substitution  !! : previous command  !!string: previous command with string appended  !N : command number N in history !-N: N-th command back from the current command !-N: N-th command back from the current command  !string : most recent command that starts with string  !?string?: most recent command that contains string  !$: last argument of previous command  !{str1}str2: get most recent command starting with str1 and append str2  ^old^new^: change old to new in previous command and execute it

Command Substitution Example % grep “this string” ReadMe.txt % ^R^r^ grep “this string” readMe.txt % more !$ more readMe.txt {file contents} % !g grep “this string” readMe.txt

Command History Modifiers  These modifiers can define the way of executing commands from history :p – display the command, but doesn’t execute :p – display the command, but doesn’t execute :s/old/new – substitute the first instance of old with new :s/old/new – substitute the first instance of old with new :gs/old/new – substitute all instances of old with new :gs/old/new – substitute all instances of old with new

Arguments Substitution  :0 – command name  :n – argument number n  ^ - first argument  $ - last argument  :n-m – arguments n through m  :n* - arguments n through the last one  * - All arguments

Example % cat test1 test2 test3 % ls !!^ % grep string !cat:1 % ^string^newstring^:p % !cat:gs/t/T

Job Control  The shell allows you to manage jobs place jobs in the background place jobs in the background move a job to the foreground move a job to the foreground suspend a job suspend a job kill a job kill a job get information about a job get information about a job

Background jobs  If you follow a command line with "&", the shell will run the job in the background. you don't need to wait for the job to complete, you can type in a new command right away. you don't need to wait for the job to complete, you can type in a new command right away. you can have a bunch of jobs running at once with a single terminal. you can have a bunch of jobs running at once with a single terminal.

Job Control Commands  jobs: list current jobs  Ctrl-z: suspends the foreground job  Ctrl-c: kill the foreground job  bg: run the most recently suspended job in the background  fg: move the most recently backgrounded job from the background into the foreground  kill: terminate a job kill [-s signal] pid (NOTE: find pid with ps) kill –l : list the kill signals

Job ID Expressions  Every job is assigned a job ID  To access job with job id, start with %: %n : job number n %n : job number n %string: job whose command line starts with string %string: job whose command line starts with string %?string: job whose command line contains string %?string: job whose command line contains string %: current job %: current job %-: previous job %-: previous job  Can use job ID with fg, bg, and kill

Job Control Examples  % find. –name myfile.txt Ctrl-zSuspended  % jobs [1] + Suspended find. -name my.txt  %emacs newfile & [2]  % jobs [1] + Suspendedfind. -name my.txt [2] - Runningemacs newfile  % bg %1 [1] find. -name my.txt & [1] Done find. -name my.txt  % kill %2 [2] Terminated emacs newfile

Directory Control  The shell maintains a directory stack  pushd dir: causes dir to be added to the directory stack and changes to that directory - previous working directory is added - previous working directory is added n : nth directory from the stack n : nth directory from the stack  popd – removes top directory from the stack and changes to that directory

Recommended Reading  Chapter 9, sections 9.3, 9.5, 9.6, 9.10, 9.12