Introduction to Scripting Workshop Highlights
Explore the key points from the Introduction to Scripting Workshop held on October 15, 2015. Discover valuable resources, instructions for Windows and Mac access, and workshop setup details. Learn about shell scripting and practical examples like word counting in data science using the command line.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
Introduction to Scripting Workshop October 15 2015
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 http://linuxcommand.org/
Other Resources How Linux Works Available at Safari Books Online
Other Resources Advanced Bash-Scripting Guide http://tldp.org/LDP/abs/html/
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 UNI@didius.cc.columbia.edu 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---- $ chmod +x wcount [ snip ]
wcount $ ls l wcount -rw-rw---- $ chmod +x wcount $ ls l wcount -rwxrwx--x [ snip ] [ 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