Introduction to Scripting Workshop October 15 2015.

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Introduction to HPC Workshop October Introduction Rob Lane HPC Support Research Computing Services CUIT.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
Nic Shulver, Scripts and Batch files Scripting in Windows and Linux What is scripting? What is it for? DOS/Windows batch files.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Introduction to UNIX/Linux Exercises Dan Stanzione.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Operating Systems Lecture 3 Shell Scripts. 2 Shell Programming 1.Shell scripts must be marked as executable: chmod a+x myScript 2. Use # to start a.
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.
Essential Unix at ACEnet Joey Bernard, Computational Research Consultant.
Chapter 5 Bourne Shells Scripts By C. Shing ITEC Dept Radford University.
1 Shell Programming – Extra Slides. 2 Counting the number of lines in a file #!/bin/sh #countLines1 filename=$1#Should check if arguments are given count=0.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction Unix-like system is everywhere Linux Android for smartphones Google Chrome OS for Chromebook Web.
File Permissions. What are the three categories of users that apply to file permissions? Owner (or user) Group All others (public, world, others)
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
Next Unix Topics Tuesday, 2/11 & 18/2014. Change Password (by 2/14/14) ssh to account on – faclinux.cse.ohio-state.edu – stdlinux.cse.ohio-state.edu passwd.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Introduction to Programming Using C An Introduction to Operating Systems.
CS252: Systems Programming Ninghui Li Slides by Prof. Gustavo Rodriguez-Rivera Topic 7: Unix Tools and Shell Scripts.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
1 Unix/Linux commands and shell programming-Part 2 (Dr. Mohamed El Bachir Menai)
Introduction to HPC Workshop October Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Unix Servers Used in This Class  Two Unix servers set up in CS department will be used for some programming projects  Machine name: eustis.eecs.ucf.edu.
Sed. Class Issues vSphere Issues – root only until lab 3.
Lab 8 Overview Apache Web Server. SCRIPTS Linux Tricks.
INTRODUCTION – COMPUTERS, BASIC C++, UNIX ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY 1.
Introduction to Linux Workshop February 15, 2016.
General Computer Science for Engineers CISC 106 Lecture 03 James Atlas Computer and Information Sciences 6/15/2009.
2 nd Intro to Shell Scripting. Dates for Last Week of Class Homework 7 – Due Tuesday 5/1 by midnight Labs 7 & 8 or late ones – 8 is extra credit – Due.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Introduction to HPC Workshop March 1 st, Introduction George Garrett & The HPC Support Team Research Computing Services CUIT.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Introduction to Scripting Workshop February 23, 2016.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Computer Programming Batch & Shell Programming 9 th Lecture 김현철 컴퓨터공학부 서울대학교 2009 년 가을학기.
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
SEEM3460 Tutorial Unix Introduction.
How to Work on your METEO 473 codes from your PC at home
Tutorial of Unix Command & shell scriptS 5027
Unix Scripts and PBS on BioU
Development Environment Basics
CIRC Winter Boot Camp 2017 Baowei Liu
Prepared by: Eng. Maryam Adel Abdel-Hady
UNIX The Basics Source:
Andy Wang Object Oriented Programming in C++ COP 3330
The Linux Operating System
Shell Script Assignment 1.
INTRODUCTION TO UNIX: The Shell Command Interface
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Introduction to HPC Workshop
LING 408/508: Computational Techniques for Linguists
Unix Scripting Dave Yearke
Tutorial of Unix Command & shell scriptS 5027
Andy Wang Object Oriented Programming in C++ COP 3330
CSE 303 Concepts and Tools for Software Development
Unix Scripting Session 2 March 13, 2008.
Presentation transcript:

Introduction to Scripting Workshop October

Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT

Introduction First Intro to Scripting Workshop Thanks for agreeing to be guinea pigs! Please Leave Feedback

Introduction Will be sent out afterwards: Slides Commands cheat sheet

Other Resources Shell and Scripting Tutorial

Other Resources How Linux Works Available at Safari Books Online

Other Resources Advanced Bash-Scripting Guide

Introduction What is a shell script?

Introduction What is a shell script? A file with shell commands.

Access Windows Instructions 1.Search for putty on Columbia home page 2.Select first result 3.Follow link to Putty download page 4.Download putty.exe 5.Run putty.exe

Access Mac Instructions 1.Run terminal

Access Mac (Terminal) $ ssh Windows (Putty) Host Name: didius.cc.columbia.edu

Access Aside System: cunix.columbia.edu User: Your UNI

Workshop Setup $ mkdir workshop $ cd workshop $ cp /tmp/workshop/*.

Command Line Example Word Count from “Data Science at the Command Line” - Jeroen Janssens

wcount $ cat wcount cat alice.txt | tr …

wcount $ wcount

wcount $ wcount -bash: wcount: command not found

wcount $./wcount

wcount $ wcount -bash:./wcount:Permission denied

wcount $ ls –l wcount

wcount $ ls –l wcount -rw-rw---- [ snip ]

wcount $ ls –l wcount -rw-rw---- [ snip ] $ chmod +x wcount

wcount $ ls –l wcount -rw-rw---- [ snip ] $ chmod +x wcount $ ls –l wcount -rwxrwx--x [ snip ]

wcount $./wcount Should work this time.

wcount Choose an editor nano  Recommended default vi emacs

wcount Choose an editor nano  Recommended default vi emacs

nano Nano commands are on back of cheat sheet. ^ means “hold down control”

Edit wcount $ nano wcount

#! Add “#!” to first line #!/bin/sh cat alice.txt | tr …

#! $./wcount Still works.

#! Some #! first lines you might see #!/bin/sh #!/usr/bin/perl #!/usr/bin/python

Variables $ file=alice.txt $ echo $file alice.txt

Variables 1.Add file=alice.txt to wcount. 2.Replace cat alice.txt with the variable.

Variables #!/bin/sh file=alice.txt cat “$file” | tr …

Variables Why put quotes around $file? cat “$file” | tr …

Command Line Parameters Change wcount so any file can be specified from the command line. $./wcount moby.txt

Command Line Parameters Change wcount so any file can be specified from the command line. $./wcount moby.txt  $1

Command Line Parameters 1.Create a new file named “param” 2.Put the #! directive on the first line 3.One bash line: “echo $1” 4.Save and make executable 5.Run it

Command Line Parameters $ cat param #!/bin/sh echo $1

Command Line Parameters $./param $./param alice.txt $./param aaa bbb ccc

Command Line Parameters Update wcount to use $1 instead of alice.txt.

Command Line Parameters Before: file=alice.txt After: file="$1"

Command Line Parameters Update param to print out $# echo $# echo $1 Run it with different numbers of parameters

if if [[ condition ]] then do something fi

[, [[, (( [ : Standard comparison [[ : Extended comparison (( : Mathematical comparison

[, [[, (( [ : Standard comparison [[ : Extended comparison  (( : Mathematical comparison

Comparison with [[ if [[ “$count” -eq 100 ]] -eq : equals -ne : not equal -gt : greater than …etc.

if if [[ $# -ne 1 ]] then do something fi

if if [[ $# -ne 1 ]] then echo “Usage: wcount file” exit 1 fi

if $./wcount $./wcount alice.txt $./wcount alice.txt junk

if if [[ ! –f “$file” ]] then echo “Error: File $file not found.” exit 1 fi

File Tests Common tests -e : File exists -f : File is “regular” -d : File is a directory …many more

if if [[ ! –f “$file” ]] then echo “Error: File $file not found.” exit 1 fi

Add lines parameter Show the five most common words: $./wcount alice.txt 5

while i=7 while (( $i > 4 )) do echo $i i=`expr $i - 1` done

for for i in aa bb cc do echo $i done for file in `ls` do ls $file done

readyourmind A silly impolite script but it shows a few more things. read : read input case : another way to control flow

End of Slides Questions?