Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

Similar documents
Shells and Shell Programming

Shells and Shell Programming

Assignment clarifications

Shell Programming (bash)

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Introduction to the Shell

bash, part 3 Chris GauthierDickey

EECS2301. Lab 1 Winter 2016

Chapter 9. Shell and Kernel

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Unix Processes. What is a Process?

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Linux shell programming for Raspberry Pi Users - 2

Review of Fundamentals

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

Implementation of a simple shell, xssh

System Programming. Unix Shells

Part 1: Basic Commands/U3li3es

CHAPTER 3 SHELL PROGRAMS: SCRIPTS

Command-line interpreters

Today. Review. Unix as an OS case study Intro to Shell Scripting. What is an Operating System? What are its goals? How do we evaluate it?

Linux Command Line Interface. December 27, 2017

Introduction to UNIX Shell Exercises

5/20/2007. Touring Essential Programs

UNIX Kernel. UNIX History

ACS Unix (Winter Term, ) Page 21

Linux & Shell Programming 2014

Introduction to UNIX Part II

Chap2: Operating-System Structures

5/8/2012. Specifying Instructions to the Shell Chapter 8

Linux shell scripting Getting started *

CST Algonquin College 2

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

UNIX Shell Programming

Introduction: What is Unix?

Processes and Shells

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell.

UNIX shell scripting

Bash command shell language interpreter

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

COMP 4/6262: Programming UNIX

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Answers to AWK problems. Shell-Programming. Future: Using loops to automate tasks. Download and Install: Python (Windows only.) R

Perl and R Scripting for Biologists

A shell can be used in one of two ways:

UNIX System Programming Lecture 3: BASH Programming

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

22-Sep CSCI 2132 Software Development Lecture 8: Shells, Processes, and Job Control. Faculty of Computer Science, Dalhousie University

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

CS246 Spring14 Programming Paradigm Notes on Linux

Introduction to Shell Scripting

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

System Administration

Introduction to Linux

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

Introduction to Linux

Unix Shell Environments. February 23rd, 2004 Class Meeting 6

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

CHAPTER 2 THE UNIX SHELLS

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Unix Shells and Other Basic Concepts

Lecture 8. Introduction to Shell Programming. COP 3353 Introduction to UNIX

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

CS370 Operating Systems

Advanced Linux Commands & Shell Scripting

Scripting Languages Course 1. Diana Trandabăț

Last Time. on the website

Implementation of a simple shell, xssh

The Online Unix Manual

UNIX Essentials Featuring Solaris 10 Op System

UNIX 2 OPERATING SYSTEM

Introduction. Let s start with the first set of slides

Standard. Shells. tcsh. A shell script is a file that contains shell commands that perform a useful function. It is also known as shell program.

Bourne Shell Reference

Shell Programming Systems Skills in C and Unix

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Introduction to Linux. Fundamentals of Computer Science

Bash Programming. Student Workbook

Unix basics exercise MBV-INFX410

Basic Linux (Bash) Commands

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

CSC209 Review. Yeah! We made it!

Lab 2: Implementing a Shell COMPSCI 310: Introduction to Operating Systems

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Lab 2: Linux/Unix shell

Shells & Shell Programming (Part B)

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

What is the Shell. Whenever you login to a Unix system you are placed in a program called the shell. All of your work is done within the shell.

(a) About Unix. History

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

CSC UNIX System, Spring 2015

Transcription:

Shells A shell is a command line interpreter that is the interface between the user and the OS. The shell: analyzes each command determines what actions are to be performed performs the actions Example: wc l file1 > file2 2

Which shell? sh Bourne shell Most common, other shells are a superset Good for programming csh or tcsh command-line default on CDF C-like syntax Best for interactive use. Not good for programming. bash default on Linux (Bourne again shell) Based on sh, with some csh features. korn written by David Korn Based on sh Some claim best for programming. Commercial product. 3

bash versus sh On the CDF machines, when you run sh, you are actually running bash. bash is a superset of sh. For CSC209, you will be learning only the features of the language that belong to sh. 4

Common shell facilities Input-output redirection prog < infile > outfile ls >& outfile ls > outfile 2>&1 Pipelining commands # csh stdout and stderr # sh stdout and stderr send the output from one command to the input of the next. ls -l wc ps aux grep krueger sort 5

Job Control A job is a program whose execution has been initiated by the user. At any moment, a job can be running or suspended. Foreground job: a program which has control of the terminal Background job: runs concurrently with the parent shell and does not take control of the keyboard. Start a job in the background by appending & Commands: ^Z, jobs, fg, bg, kill 6

File Name Expansion ls *.c rm file[1-6].? cd ~/bin ls ~krueger ls *.[^oa] - ^ in csh,! in sh * stands in for 0 or more characters? stands in for exactly one character [1-6] stands in for one of 1, 2, 3, 4, 5, 6 [^oa] stands in for any char except o or a ~/ stands in for your home directory ~krueger stands in for krueger s home directory 7

Exceptions ls.* doesn t do what you would expect Why?.* matches. and.. because. files are hidden files, we don t usually want to include them in our operations. How to get around this feature? ls -d.* - still catches. and.. ls.??* - misses files like.b Challenge: find other ways. 8

Shell Programming (Bourne shell) Commands run from a file in a subshell A great way to automate a repeated sequence of commands. File starts with #!/bin/sh absolute path to the shell program not the same on every machine. Can also write programs interactively by starting a new shell at the command line. Tip: this is a good way to test your shell programs 9

In a file: #! /bin/sh echo "Hello World!" Example At the command line: skywolf% sh sh-2.05b$ echo "Hello World" Hello World sh-2.05b$ exit exit skywolf% 10

Commands You can run any program in a shell by calling it as you would on the command line. When you run a program like grep or ls in a shell program, a new process is created. There are also some built-in commands where no new process is created. echo set read exit test shift wait "man sh to see all builtins. 11

Variables local variables spaces matter name=value assignment $name replaced by value of name variables can have a single value or list of values. Single value: bindir="/usr/bin" List of values (separated by spaces): searchdirs="~/tests $HOME/test2." 12

Example: ($ is the default sh prompt) $ bindir="/usr/bin" $ searchdirs="~/tests $HOME/test2." $ echo $searchdirs ~/tests /u/krueger/test2. $ echo $bindir /usr/bin 13

String Replacement Scripting languages are all about replacing text or strings, unlike other languages such as C or Java which are all about data structures. Variables are placeholders where we will substitute the value of the variable. Example: iters="1 2 3 4" for i in $iters; do done echo $i = for i in 1 2 3 4; do done echo $i 14

Quoting Double quotes inhibit wildcard replacement only. Single quotes inhibit wildcard replacement, variable substitution and command substitution. Back quotes cause command substitution. Practice and pay attention. Single and double quotes are on the same key. Back quote is often on the same key as ~. 15

Quoting example $ echo Today is date Today is date $ echo Today is `date` Today is Thu Sep 19 12:28:55 EST 2002 $ echo Today is `date` Today is Thu Sep 19 12:28:55 EST 2002 $ echo Today is `date` Today is `date` " double quotes single quote ` - back quote 16

Another Quoting Example What do the following statements produce if the current directory contains the following nonexecutable files? a b c $ echo * $ echo ls * $ echo `ls *` $ echo ls * $ echo ls * $ echo `*` " double quotes single quote ` - back quote 17

More on Quoting Command substitution causes another process to be created. Which is better? What is the difference? src=`ls *.c` or src= *.c 18