Bourne Shell (ch 8) Overview. Bourne Shell. Bourne Shell. Bourne Shell. Bourne Shell. Redirect standard error. Redirect standard error

Similar documents
Chapter 9. Shell and Kernel

Part 1: Basic Commands/U3li3es

Useful Unix Commands Cheat Sheet

Shell script/program. Basic shell scripting. Script execution. Resources. Simple example script. Quoting

Review of Fundamentals

CST Algonquin College 2

Advanced Shell Usage III.A

Shell Programming (ch 10)

Lecture 4. Log into Linux Reminder: Homework 1 due today, 4:30pm Homework 2 out, due next Tuesday Project 1 out, due next Thursday Questions?

Using bash. Administrative Shell Scripting COMP2101 Fall 2017

Bourne Shell Reference

UNIX Shell Programming

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Shell Start-up and Configuration Files

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.

Log into Linux Reminders: Homework 1 due today; Homework 2 due on Thursday Questions?

CS Unix Tools & Scripting

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Input/Output (I/O) Re-direction

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

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

Environment Variables

Implementation of a simple shell, xssh

Software I: Utilities and Internals. What isbash?

Title:[ Variables Comparison Operators If Else Statements ]

Linux shell programming for Raspberry Pi Users - 2

Lecture #10 - Interactive Korn Shell (Chapter 11)

Linux 系统介绍 (III) 袁华

Study Guide. The System Administrator s Guide to Bash Scripting

bash, part 3 Chris GauthierDickey

Implementation of a simple shell, xssh

Useful information mostly written by me, the conspicuous exception being the bash manpage... BASH(1) 1998 Apr 1 BASH(1)

CSE 391 Lecture 5. Intro to shell scripting

Bash command shell language interpreter

Bash Check If Command Line Parameter Exists

Basic Linux (Bash) Commands

CSE 390a Lecture 5. Intro to shell scripting

Linux shell scripting Getting started *

Topic 2: More Shell Skills

85321, Systems Administration Chapter 6: The shell

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

Work Effectively on the Command Line

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

Processes and Shells

Unix Processes. What is a Process?

Environment Variables

CS Unix Tools. Lecture 3 Making Bash Work For You Fall Hussam Abu-Libdeh based on slides by David Slater. September 13, 2010

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center

CHAPTER 3 SHELL PROGRAMS: SCRIPTS

Shell Scripting. Xiaoxu Guan High Performance Computing, LSU February 17, 2016

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Introduction to the Shell

Topic 2: More Shell Skills. Sub-Topic 1: Quoting. Sub-Topic 2: Shell Variables. Difference Between Single & Double Quotes

CSC UNIX System, Spring 2015

Sub-Topic 1: Quoting. Topic 2: More Shell Skills. Sub-Topic 2: Shell Variables. Referring to Shell Variables: More

How to print or access value of UDV (User defined variables)

Part III. Shell Config. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

Introduction to Linux

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

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Introduction to Linux Basics Part II. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Introduction to Linux

Bash Programming. Student Workbook

SOFTWARE ARCHITECTURE 3. SHELL

Linux at the Command Line Don Johnson of BU IS&T

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

Shells and Processes. Bryce Boe 2012/08/08 CS32, Summer 2012 B

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

Bourne Shell Programming Topics Covered

Chapter 4. Unix Tutorial. Unix Shell

UNIX System Programming Lecture 3: BASH Programming

Bash scripting basics

Introduction to UNIX Command Line

Introduction to Bash Programming. Dr. Xiaolan Zhang Spring 2013 Dept. of Computer & Information Sciences Fordham University

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?

Introduction to Linux/Unix. Xiaoge Wang

Last Time. on the website

Essentials for Scientific Computing: Bash Shell Scripting Day 3

I/O and Shell Scripting

Basics. I think that the later is better.

Pro Bash Programming. Scripting the GNU/Linux Shell. Second Edition. Jayant Varma. Chris F. A. Johnson. Hi mm mm. mmmm mmmm HHi

Assignment clarifications

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

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

UNIX Essentials Featuring Solaris 10 Op System

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

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

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

About this course 1 Recommended chapters... 1 A note about solutions... 2

Shell Programming for System Administrators Student Guide

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

System Programming. Unix Shells

Shell scripting Scripting and Computer Environment - Lecture 5

Welcome to the Bash Workshop!

Introduction To. Barry Grant

28-Nov CSCI 2132 Software Development Lecture 33: Shell Scripting. 26 Shell Scripting. Faculty of Computer Science, Dalhousie University

D. Delete the /var/lib/slocate/slocate.db file because it buffers all search results.

CMPS 12A Introduction to Programming Lab Assignment 7

Common File System Commands

Transcription:

Overview (ch 8) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng Admin determines which shell you use bash is the default shell in most of Linux systems /bin/bash Shell start-up /etc/profile (for all users) ~/.bash_profile or ~/bash_login ~/.bashrc and /etc/bashrc /etc/profile, ~/.bash_profile ~/.bashrc /etc/bashrc 1 2 echo this is y > y cat y cat x cat x y > log cat x y tr [a-z] [A-Z] 3 4 File descriptor 0: std input, 1: std output, 2: std error cat x y 1> log 2> err cat err Combine std input and std error (&>) cat x y &> log 5 6 1

Duplicate a file descriptor (>&) Left side: original channel Right side: current channel cat x y 1> log 2>&1 Duplicate a file descriptor (>&) Left side: original channel Right side: current channel cat x y 1>log 2>log cat x y 2>&1 1> log cat y x 1>log 2>log 7 8 Duplicate a file descriptor (>&) Left side: original channel Right side: current channel cat x y 1>&2 cat x y 2>err 1>&2 First script cat > whoson date echo Current Users: who CTRL+D cat x y 1>&2 tr [a-z] [A-Z] 9 10 Execute script chmod a+x whoson./whoson Execute script chmod a+x whoson./whoson Subshell takes commands from the script file chmod a-x whoson bash whoson chmod a-r whoson bash whoson 11 12 2

Environmental variables echo $PATH Search directories in order cd ~ whoson PATH=$PATH:~/it244 whoson Specify a shell in scripts (#!) cat >dash_script #!/bin/dash ps $$ ^D./dash_script Comments in script (#) 13 14 Separate and Group Commands Separation ( ; \ ) echo start; ls; echo end echo hello \ (newline) world echo hello \\ (newline) Separate and Group Commands Separation ( ; \ ) Within quotes echo Please choose: (newline) 1. yes (newline) 2. no echo Please choose: \(newline) 1. yes \(newline) 2. no 15 16 Separate and Group Commands Separation ( & ) Pipe ls l grep hello less Background jobs tail f log & cat > log Separate and Group Commands Group ( ) (ls -l; tail -f log; ls)& fg %1 CTRL+C 17 18 3

Job Control Suspend, fore/background ls& exetest& exetest& tail f log& jobs + is the last job, - is the previous job Letters, digits, and underscores Start with letters or underscores Valid: A123, _X_, MY_PATH Invalid: 123_ABC, MY-PATH, A&B 19 20 MYNAME=bo export MYNAME=bo echo $MYNAME MYNAME= bo sheng MYNAME= bo sheng MYNAME=bo\ sheng echo $MYNAME echo $MYNAME echo \$MYNAME 21 22 CMD=echo $CMD $MYNAME $CMD my name is $MYNAME. CMD= echo hello world $CMD CMD= echo $MYNAME $CMD Pathname expansion HELLO=hello* echo $HELLO echo $HELLO echo hello* 23 24 4

Braces { } PR=IT echo $PR244 $PR110 echo ${PR}244 $PR{110} PR=CS echo ${PR}244 $PR{110} Variable assignment in command lines (MYNAME=sheng; echo $MYNAME) echo $MYNAME echo echo $MYNAME > my_script MYNAME=sheng./my_script 25 26 Variable domain./my_script export MYNAME=bo./my_script Remove a variable person= echo $person unset person 27 28 Variable Attributes readonly variables person=zach echo $person readonly person person=helen readonly Variable Attributes declare and typeset Attribute Meaning -a An array -f A function -i An integer -r readonly -x Export (global variable) declare person1=max declare r person2=zach 29 30 5

Variable Attributes declare and typeset Attribute Meaning -a An array -f A function -i An integer -r readonly -x Export (global variable) declare rx person3=helen declare x person4 Variable Attributes declare and typeset Attribute Meaning -a An array -f A function -i An integer -r readonly -x Export (global variable) declare i COUNT 31 32 Variable Attributes List/remove attributes declare -r declare -x Processes What s a process Execution of a command Shell is a process declare +x person4 declare -x declare +r person2 fork() Two identical processes, but one is the parent and the other is the child. 33 34 Processes Execute a command shell shell fork execute the command fork sleep execute the command (background) PID and PPID sleep 10& ps -f Processes Builtins Variables cat > my_script declare -r sleep 10./my_script & ps -f 35 36 6

Keyword Variables PATH HOME HOSTNAME PS1/PS2 PS1=* PS1=$HOSTNAME PS1= \d \h \u - (table in Pg 310) PS2= --- Variables HISTSIZE HISTFILE HISTFILESIZE History cat ~/.bash_history history less history tail 37 38 History expansion!! Variable expansion echo $person echo $person echo $person Tilde expansion echo ~/it244 echo ~shengbo echo ~+ echo ~- 39 40 Pathname/filename expansion echo colors* echo zzz* echo colors* $person echo colors* $person var=colors* echo $var echo $var echo $var Command substitution $(command) echo $(pwd) mypwd=$(pwd) 41 42 7

Arithmetic expansion echo 1+1 echo $((1+1)) echo there are $((60*60*24)) seconds in a day x=10;y=20 echo $((x*2+y/4)) Arithmetic expansion cat > age_check >echo "how old are you?" >read age >echo "you'll be 60 in $((60-age)) years." 43 44 Order of expansion tofile= > log echo hello $tofile a=hello* echo $a echo $a 45 8