Welcome to the Bash Workshop!

Similar documents
Welcome to the Bash Workshop!

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

Make sure the parameter expansion is quoted properly. It may not be necessary here, but it is good practice.

Bash command shell language interpreter

Bash Programming. Student Workbook

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

Output with printf Input. from a file from a command arguments from the command read

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2017

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

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

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

More Scripting Todd Kelley CST8207 Todd Kelley 1

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

UNIX System Programming Lecture 3: BASH Programming

A shell can be used in one of two ways:

Overview of the UNIX File System

CSE 15L Winter Midterm :) Review

Assignment clarifications

Shell Programming (bash)

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

GNU Bash. an introduction to advanced usage. James Pannacciulli Systems Engineer.

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

Review of Fundamentals

Overview of the UNIX File System. Navigating and Viewing Directories

Shells and Shell Programming

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

Title:[ Variables Comparison Operators If Else Statements ]

Lab 4: Shell scripting

CS Unix Tools & Scripting

More Scripting and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

Introduction to the Shell

9.2 Linux Essentials Exam Objectives

Scripting. More Shell Scripts. Adapted from Practical Unix and Programming Hunter College

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

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

CSE 374: Programming Concepts and Tools. Eric Mullen Spring 2017 Lecture 4: More Shell Scripts

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash

Linux shell programming for Raspberry Pi Users - 2

CS Unix Tools & Scripting

Bourne Shell Reference

1 Installation (briefly)

Windshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A.

Linux File System and Basic Commands

COMP 2718: Shell Scripts: Part 1. By: Dr. Andrew Vardy

Implementation of a simple shell, xssh

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

Shell Programming (Part 2)

Linux shell scripting Getting started *

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

Unix Shell scripting. Dr Alun Moon 7th October Introduction. Notation. Spaces

COMS 6100 Class Notes 3

Basic Linux (Bash) Commands

UNIX shell scripting

Shells and Shell Programming

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2018

Linux Command Line Interface. December 27, 2017

do shell script in AppleScript

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

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

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

UNIX Shell Programming

Chapter 4. Unix Tutorial. Unix Shell

Shell Start-up and Configuration Files

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Essentials for Scientific Computing: Bash Shell Scripting Day 3

Understanding bash. Prof. Chris GauthierDickey COMP 2400, Fall 2008

ACS Unix (Winter Term, ) Page 21

Linux Systems Administration Getting Started with Linux

System Programming. Unix Shells

Here redirection. Case statement. Advanced Unix Tools Lecture 6 CS214 Spring 2004 Friday March 5, 2004

More Scripting Techniques Scripting Process Example Script

Simple Shell Scripting for Scientists

Bash Check If Command Line Parameter Exists

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

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Computer Systems and Architecture

Shells & Shell Programming (Part B)

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

Shell script. Shell Scripts. A shell script contains a sequence of commands in a text file. Shell is an command language interpreter.

CSCI 2132: Software Development

Last Time. on the website

Advanced Linux Commands & Shell Scripting

file:///users/cerdmann/downloads/ harvard-latest.html

COMP 4/6262: Programming UNIX

Lab 4: Bash Scripting

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

Regex, Sed, Awk. Arindam Fadikar. December 12, 2017

CS Unix Tools & Scripting Lecture 7 Working with Stream

Implementation of a simple shell, xssh

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

EECS2301. Lab 1 Winter 2016

Unix. Examples: OS X and Ubuntu

Learn Bash The Hard Way

INTRODUCTION TO SHELL SCRIPTING ITPART 2

Introduction to Unix: Fundamental Commands

Table of Contents. 1. Introduction. 2. Environment. 3. Shell Scripting Shell Scripting Introduction

Bash scripting basics

Learn Bash the Hard Way

CS Unix Tools. Fall 2010 Lecture 5. Hussam Abu-Libdeh based on slides by David Slater. September 17, 2010

Transcription:

Welcome to the Bash Workshop! If you prefer to work on your own, already know programming or are confident in your abilities, please sit in the back. If you prefer guided exercises, are completely new to programming, or want to have your hands held, please sit in the front. 1

Bash Workshop Bash Workshop 1

Table of Contents What will we do today? Theory Exercises What is bash? The basics Bash Workshop 2

Shells Bash is a not a programming language. It is a shell It is an interface between you and your computer It allows you to access the operating system s services (i.e. run programs) It is not designed as a programming language, but can be used as such Bash Workshop 3

Shells Bash is not the only shell there is. sh, ksh, zsh, fish, dash... Most commands work in any shell, but some don t Usually this doesn t matter too much Bash Workshop 4

Shells Bash scripts are not programming Glue existing programs together to create new ones It s possible to write entire programs, but please don t Bash Workshop 5

How to bash Look, a bash script #!/ bin / bash echo Hello World echo Bash is awesome # Now some fun stuff : sudo zypper update notify - send Update complete feh --bg - fill pictures / fancy_wallpaper. jpg youtube -dl -o Video.%( ext )s https :// www. youtube. com / watch?v= laigb1lfpbw Bash Workshop 6

How to bash What bash can do Automate anything you can do from a console Let several separate programs work together Bash Workshop 7

Commands All about commands Everything is a command Bash Workshop 8

Commands Kinds of commands Functions are a sequence of bash commands that have been given a name Programs are external programs that are installed on your system Builtins are small utilities that are part of bash Keywords are like builtins, but with special parsing rules Bash Workshop 9

Commands Why is this so important? if and while are builtins [[ is a keyword Bash Workshop 10

Commands Example wrong: [[1 <3]] correct: [[ 1 < 3 ]] Bash Workshop 11

Commands Repeat after me If there s brackets, you probably need spaces. Bash Workshop 12

Strings All about strings Everything is a string Bash Workshop 13

Strings Strings and word splitting A string is a sequence of characters that is treated as a unit Commands are strings, too Strings are split at every space, tab, or newline unless they re in quotes Bash Workshop 14

Strings Meaning of strings echo Hello World echo, Hello and World are single strings The first string becomes the command, all following become arguments echo Hello World Here, Hello World is just one string Bash Workshop 15

Strings Repeat after me Every word is a single argument unless you use quotes. Bash Workshop 16

All about return values All about return values Every command returns a value Bash Workshop 17

All about return values Return values What you run echo Hello World What you see Hello World What bash sees 0 Bash Workshop 18

All about return values Why? Every command returns a number, its return value 0 means success Everything else means there was an error Some commands also print to stdout - that s what you see. Bash Workshop 19

All about return values Why is that important? &&,, if and while all act based on the return value of something They disregard that command s actual output Bash Workshop 20

All about return values Example if xrandr grep HDMI -0 connected # if HDMI monitor is connected then feh --bg - fill ~/ bigwallpaper. jpg # set the larger wallpaper fi Bash Workshop 21

Expansion Bash doesn t only run commands Tilde expansion ~/files becomes /home/alinea/files Variable expansion $BROWSER becomes Firefox Arithmetic expansion $(( 1 + 4 )) becomes 5 Command substitution $( pwd ) becomes /home/alinea/scripts Pathname expansion (or globbing) files/qui* becomes files/quicknotes files/quiz Bash Workshop 22

Expansion Bash doesn t only run commands Expansion happens before any command is run Double quotes ( ) don t prevent expansion, but single quotes ( ) do. Expansion happens before word splitting Bash Workshop 23

Expansion The issue with word splitting var = Unimportant File. odt rm $var # Variable expansion becomes rm Unimportant File. odt Bash Workshop 24

Expansion The issue with word splitting The correct way rm " $var " Bash Workshop 25

Expansion Repeat after me: If there s a dollar, you probably need quotes! Bash Workshop 26

The whole point of bash Why is bash awesome? Bash can easily invoke any programs and connect them Bash is like glue Bash Workshop 27

How to write a bash script How to write a bash script I want a script that searches youtube and downloads the first video it finds Bash Workshop 28

How to write a bash script Splitting it up Search youtube Download video Bash Workshop 29

How to write a bash script Google for a program that already does what you need youtube-dl can download a video from youtube youtube -dl -o Video.%( ext )s https :// www. youtube. com / watch?v= laigb1lfpbw Bash Workshop 30

How to write a bash script Splitting it up even further Search youtube Download youtube results website Search website text Find first youtube video link Download video Bash Workshop 31

What happens now? Hands on! Self-driven exercises Self study using a guide Try some of our exercises Choose the exercises you find interesting! No need to go in order. Guided exercises Solve easy exercises in plenum Tailored to complete beginners Please sit in the front Bash Workshop 32

What happens now? Course material These slides, exercise sheet and bash guide: http://thealternative.ch/index.php?view=knowhow Theme by Christian Horea, CC BY Bash Workshop 33