Lab 5: Complex Inputs.

Slides:



Advertisements
Similar presentations
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Advertisements

EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Linux+ Guide to Linux Certification, Second Edition
Basic Unix Dr Tim Cutts Team Leader Systems Support Group Infrastructure Management Team.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
Shell Script Examples.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
CTEC 1863 – Operating Systems Shell Scripting. CTEC F2 Overview How shell works Command line parameters –Shift command Variables –Including.
Writing Shell Scripts ─ part 1 CSE 2031 Fall September 2015.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
An Introduction to Unix Shell Scripting
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
Shell Scripting Todd Kelley CST8207 – Todd Kelley1.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
CS 6560 Operating System Design Lecture 3:Tour of GNU/Linux.
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.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux+ Guide to Linux Certification, Third Edition
Shell Programming Any command or a sequence of UNIX commands stored in a text file is called a shell program. It is common to call this file a command.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Beyond sh Not everyone is as fond of UNIX as most other people. The tutorial talks about the dark side of UNIX.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
Writing Scripts Hadi Otrok COEN 346.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Shell Scripting – Putting it All Together. Agenda Escaping Characters Wildcards Redirecting Output Chaining and Conditional Chaining Unnamed and Named.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2014 Lecture 3 – I/O Redirection, Shell Scripts.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Shell scripts – part 1 Cs 302. Shell scripts  What is Shell Script? “Shell Script is series of command written in plain text file. “  Why to Write Shell.
Bash Shell Scripting 10 Second Guide.
A Playful Introduction to Programming by Jason R. Briggs
Introduction to Shells
LINUX FOR BEGINNERS Because everyone needs Fundamentals
Writing Shell Scripts ─ part 1
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
Agenda Bash Shell Scripting – Part II Logic statements Loop statements
The UNIX Shell Learning Objectives:
CAP652 Lecture - Shell Programming
CSE 374 Programming Concepts & Tools
Some Linux Commands.
Lecture 9 Shell Programming – Command substitution
The Linux Operating System
LINUX FOR BEGINNERS Because everyone needs Fundamentals
CSE 303 Concepts and Tools for Software Development
Using Linux Commands Lab 3.
Agenda Control Flow Statements Purpose test statement
What is Bash Shell Scripting?
John Carelli, Instructor Kutztown University
The Unix File System.
Writing Shell Scripts ─ part 1
CSE 303 Concepts and Tools for Software Development
Beginning Python Programming
CSC 4630 Meeting 4 January 29, 2007.
Introduction to Bash Programming, part 3
Basic shell scripting CS 2204 Class meeting 7
Presentation transcript:

Lab 5: Complex Inputs

What is a complex input? Something other than basic alphanumeric strings Non-Complex Inputs: Christo pitbull password123 somethingelse7 Complex Inputs: $PATH “Huh” “Hello world\n” \0 *.sh ?.py

Important Bash Complex Inputs There are some special bash variables that you should take note of: $PATH $USER $HOME $SHELL Use the echo command to see what these variables are

Whitespace The most overlooked form of complex inputs What is the difference between the following commands? mkdir resource files mkdir 'resource files' The first will create two directories named “resource” and “files” The second will create one directory named “resource files” The same thing will happen for regular files

Quoting Quoting is how you deal with anything that has spaces Now you can run mkdir 'resource files' and it will create one directory There are two types of quoting Strong quoting – uses single quotes Weak quoting – uses double quotes

Strong Quoting Strong quoting makes use of the single quotes This tells the shell to interpret everything it reads literally echo '$HOME' This outputs $HOME

Weak Quoting Weak quoting makes use of double quotes This tells the shell to interpret any variables or escape characters echo “$HOME” This outputs /home/ubuntu The shell will see $HOME and interpret it and print out the home directory

Wildcards There are three types of wildcards: * (asterisk) ? (question mark) [] (square brackets)

Hitchhiker's Guide to the Galaxy A brief history before we get into the functionality of the asterisk 42: The answer to life, universe, everything Anyone know why that is? 42 in binary is 00101010 00101010 in ASCII is the asterisk

Asterisk Wildcard Since we now know the background history of the asterisk and why it is so important, we can discuss how it's used The asterisk represents any number of characters Try the command file * in any directory that has some files

Question Mark Wildcard Rather than representing multiple characters like the asterisk, the question mark will only represent one character Run the command ls -l example?.txt

Square Brackets Wildcard The square brackets wildcard offers some flexibility in which characters you'd like to substitute With the square brackets, you can only substitute certain characters Try the command file l[aeiou]st.txt This will only return file names with the second character as a vowel and the other characters being fixed

Combining All the Wildcards The wildcards can be combined with each other to give more flexibility in your searches Examples: ls -l *.?? (this will search for any file which has a file extension which is two characters long) file [nmc]* (this will search for anything which starts with “n”, “m”, or “c” There are endless ways to put together wildcards

Escape Characters In the terminal, programming languages, etc. there are a set of characters that invoke a different interpretation of the character Examples: \n \t \”

Escape Characters in Action To see how escape characters affect basic strings, use the echo command with the -e argument echo -e “Hello\nWorld” echo -e “Hello\tWorld” echo -e “Hello\vWorld”