Introduction to Scripting Workshop Highlights

Slide Note
Embed
Share

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.


Uploaded on Oct 09, 2024 | 0 Views


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


  1. Introduction to Scripting Workshop October 15 2015

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

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

  4. Introduction Will be sent out afterwards: Slides Commands cheat sheet

  5. Other Resources Shell and Scripting Tutorial http://linuxcommand.org/

  6. Other Resources How Linux Works Available at Safari Books Online

  7. Other Resources Advanced Bash-Scripting Guide http://tldp.org/LDP/abs/html/

  8. Introduction What is a shell script?

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

  10. 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

  11. Access Mac Instructions 1. Run terminal

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

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

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

  15. Command Line Example Word Count from Data Science at the Command Line - Jeroen Janssens

  16. wcount $ cat wcount cat alice.txt | tr

  17. wcount $ wcount

  18. wcount $ wcount -bash: wcount: command not found

  19. wcount $ ./wcount

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

  21. wcount $ ls l wcount

  22. wcount $ ls l wcount -rw-rw---- [ snip ]

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

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

  25. wcount $ ./wcount Should work this time.

  26. wcount Choose an editor nano Recommended default vi emacs

  27. wcount Choose an editor nano Recommended default vi emacs

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

  29. Edit wcount $ nano wcount

  30. #! Add #! to first line #!/bin/sh cat alice.txt | tr

  31. #! $ ./wcount Still works.

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

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

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

  35. Variables #!/bin/sh file=alice.txt cat $file | tr

  36. Variables Why put quotes around $file? cat $file | tr

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

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

  39. 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

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

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

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

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

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

  45. if if [[ condition ]] then do something fi

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

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

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

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

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

Related


More Related Content