Linux Shells. Linux Shells. Book Chapter 5. What is a shell? Examples: Linux default shell /bin/bash. How do I know what shell I am running?

Similar documents
Command Line Crash Course For Unix

Bash Guide for Beginners

Unix Scripts and Job Scheduling

AN INTRODUCTION TO UNIX

Hands-On UNIX Exercise:

HP-UX Essentials and Shell Programming Course Summary

Advanced Bash Scripting. Joshua Malone

CS2720 Practical Software Development

Command Line - Part 1

ICS 351: Today's plan

An A-Z Index of the Apple OS X command line (TERMINAL) The tcsh command shell of Darwin (the open source core of OSX)

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

Cisco Networking Academy Program Curriculum Scope & Sequence. Fundamentals of UNIX version 2.0 (July, 2002)

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

Linux command line. An introduction to the Linux command line for genomics. Susan Fairley

Unix Sampler. PEOPLE whoami id who

A Crash Course on UNIX

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script

UNIX, Shell Scripting and Perl Introduction

Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes

Lecture 25 Systems Programming Process Control

The Linux Operating System and Linux-Related Issues

A UNIX/Linux in a nutshell

CS Unix Tools & Scripting Lecture 9 Shell Scripting

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

Introduction to Shell Programming

Introduction to. UNIX Bob Booth December 2004 AP-UNIX2. University of Sheffield

Thirty Useful Unix Commands

system or read a good Unix book from the DESY library (e.g. Mark Sobell, APractical Guide to

An Introduction to the Linux Command Shell For Beginners

Tour of the Terminal: Using Unix or Mac OS X Command-Line

Beginners Shell Scripting for Batch Jobs

CS10110 Introduction to personal computer equipment

New Lab Intro to KDE Terminal Konsole

Advanced UNIX Techniques Lee Ann Lee Revised by Wendy Kajiyama

UNIX / Linux commands Basic level. Magali COTTEVIEILLE - September 2009

Answers to Even- Numbered Exercises

BASH Scripting. A bash script may consist of nothing but a series of command lines, e.g. The following helloworld.sh script simply does an echo.

The Linux Operating System

Shellscript Programming Using bash

UNIX Tutorial for Beginners

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

Answers to Even-numbered Exercises

Fred Hantelmann LINUX. Start-up Guide. A self-contained introduction. With 57 Figures. Springer

Outline. Unix shells Bourne-again Shell (bash) Interacting with bash Basic scripting References

Unix the Bare Minimum

Introduction to Operating Systems

CS 2112 Lab: Version Control

Automating admin tasks using shell scripts and cron Vijay Kumar Adhikari.

Partitioning. Files on the Hard Drive. Administration of Operating Systems DO2003. Partition = Binder with index. Write file = Insert document

List of FTP commands for the Microsoft command-line FTP client

An Introduction to the C shell

Automating FTP with the CP IT

A Brief Introduction to the Use of Shell Variables

CLC Server Command Line Tools USER MANUAL

DOS Command Reference

Lecture 4. Regular Expressions grep and sed intro

Tutorial 0A Programming on the command line

INASP: Effective Network Management Workshops

Lecture 4: Writing shell scripts

UNIX: Introduction to TELNET and FTP on UNIX

HOW TO USE THIS DOCUMENT READ OBEY

SFTP SHELL SCRIPT USER GUIDE

Birmingham Environment for Academic Research. Introduction to Linux Quick Reference Guide. Research Computing Team V1.0

Open Source Computational Fluid Dynamics

Introduction to Running Hadoop on the High Performance Clusters at the Center for Computational Research

USEFUL UNIX COMMANDS

Windows PowerShell Essentials

UNIX Intro and Basic C shell Scripting

CPSC2800: Linux Hands-on Lab #3 Explore Linux file system and file security. Project 3-1

Unix Tools. Overview. Editors. Editors nedit vi Browsers/HTML Editors Mail Tools Utilities xv xman ftp

L01 Introduction to the Unix OS

Unix and Linux. David J. Scott. Department of Statistics, University of Auckland. Unix and Linux p. 1/4

Linux System Administration on Red Hat

Cygwin command line windows. Get that Linux feeling - on Windows

Introduction to Linux operating system. module Basic Bioinformatics PBF

CHAPTER 1 Getting Started with SAS in UNIX Environments

Lecture 22 The Shell and Shell Scripting

Introduction to Mac OS X

CPSC 2800 Linux Hands-on Lab #7 on Linux Utilities. Project 7-1

Command-Line Operations : The Shell. Don't fear the command line...

GNU/Linux Command Line Tools Summary

Submitting batch jobs Slurm on ecgate. Xavi Abellan User Support Section

Kleine Linux-Tricks - schneller ohne Aufwand

CPSC 226 Lab Nine Fall 2015

Networks. Inter-process Communication. Pipes. Inter-process Communication

Systems Programming & Scripting

Bash shell programming Part II Control statements

BASH scripting. Sebastian von Alfthan Scripting techniques CSC Tieteen tietotekniikan keskus Oy CSC IT Center for Science Ltd.

Digital UNIX. Command and Shell User s Guide. Digital Equipment Corporation Maynard, Massachusetts

CS 103 Lab Linux and Virtual Machines

Running your first Linux Program

Unix Shell Scripting Tutorial Ashley J.S Mills

Basic Linux and Unix commands, editing and transfering files

Introduction to Shell Scripting

SSH Connections MACs the MAC XTerm application can be used to create an ssh connection, no utility is needed.

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

13. Configuring FTP Services in Knoppix

CMSC 216 UNIX tutorial Fall 2010

Lab 1: Introduction to the network lab

Transcription:

Linux Shells Book Chapter 5 What is a shell? Examples: bash Bourne Again shell ksh tcsh Korn shell C shell 1 Linux Shells Linux default shell /bin/bash How do I know what shell I am running? echo $SHELL env 2

Shell Operations Shell invocation sequence 1. read special startup file containing initialization info 2. display prompt and wait for user command 3. execute command if end of file exit shell otherwise execute command entered 3 Shells operations Shell command examples ls ps -ef sort ul -tdumb lp \ serves as line extension character e.g.: echo this is a long command that does \ not fit in one line 4

Commands - executables Where are the shell commands? most commands invoke utility programs shell executes executable stored in file system e.g., ls (\bin\ls) 5 Commands - built-in Where are the shell commands? other commands are built-in, e.g., echo [option]... [string] which displays line of text cd bash built-ins man cd outputs bash, :,., [, alias, bg, bind, break, builtin, cd, command, compgen, complete, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, type, typeset, ulimit, umask, unalias, unset, wait - bash built-in commands, see bash(1) 6

Shell Metacharacters 7 Redirection Output Redirection Store output of process in file echo hello world > file echo more words >> file writes string into file append string to file Input Redirection use contents of file as input 8

Filename Substitution Shell wildcards * matches any string including empty string? matches any single character [..] matches any one of the chars in brackets what do the following examples display? ls -l *.c ls [A-Za-z]* ls */*.c 9 Pipes Use output of one command as input to another pipe output of one process to the input of another example ls wc -w cat /etc/passwd gawk -F: '{ print $1 }' sort 10

Pipes example: tee - read from standard input and write to standard output and files $ who tee who.capture sort ables pts/6 May 3 17:54 (gw.waterloo.com) glass pts/0 May 3 18:49 (blackfoot.utdall) posey pts/2 Apr 23 17:44 (:0.0) posey pts/4 Apr 23 17:44 (:0.0) $ cat who.capture...look at the captured data. glass pts/0 May 3 18:49 (blackfoot.utdalla) posey pts/2 Apr 23 17:44 (:0.0) posey pts/4 Apr 23 17:44 (:0.0) ables pts/6 May 3 17:54 (gw.waterloo.com) 11 Command Substitution A command surrounded by grave accents (`, back quotes) is executed and its output (after evaluation) is inserted in the command in its place. Any newlines in the output are replaced by spaces -bash-3.2$ echo the date today is `date` the date today is Mon Sep 20 10:44:18 PDT 2010 -bash-3.2$ -bash-3.2$ echo there are `who wc -l` users on the system there are 3 users on the system -bash-3.2$ 12

Sequences A series of simple commands or pipelines separated by semicolons is executed in sequence, from left to right. -bash-3.2$ who ; date; ps krings pts/0 2010-09-20 10:43 (star.cs.uidaho.edu) jeffery pts/1 2010-09-14 11:50 (clint2.cs.uidaho.edu) jeffery pts/3 2010-09-08 13:02 (75.87.248.45) Mon Sep 20 10:51:47 PDT 2010 PID TTY TIME CMD 26826 pts/0 00:00:00 bash 26941 pts/0 00:00:00 ps 13 Conditional Sequences Every Linux process terminates with an exit value 0 means normal execution nonzero indicates failure built-in commands return 1 if they fall 14

Conditional Sequences Using exit values If you specify a series of commands separated by && tokens, the next command is executed only if the previous command returns an exit code of 0. If you specify a series of commands separated by tokens, the next command is executed only if the previous command returns a nonzero exit code The && and metacharacters mirror the operation of their counterpart C operators. -bash-3.2$ gcc cpu.c &&./a.out -bash-3.2$ gcc myprog.c echo compilation failed. 15 Background Processing A command followed by the & metacharacter will be executed in the background execute several programs in background look at them using ps or top bring them to the foreground use bg, fg, ^Z 16

Background Processing A process running in the background may still output to the screen (stdout) different ways to deal with that, e.g. redirect to file redirect to dummy device, /dev/null mail to yourself, e.g. find. -name a.c -print mail glass & 17