Introduction to Linux and history

Learning outcomes:

  • Create and use a basic shellscript that includes a shebang line, comment and echo
  • Explain the different quotes and their uses
  • Modify a script using a text editor

Would you like to download my PowerPoint to follow along?

  • What is a script and why do we care?
    • Small programs that can be used for multiple things including repetitive tasks and repeated activities
    • A text file with 1 command per line
    • Scripts are also good for Complicated things you don't use often, If you need to figure it out once, why not make a script so you don't have to do it again?
    • Comments use a #
    • Always start with shbang to specify shell type, it's not required, but it makes it more clear what kind of script you're writing
    • An example tutorial for scripting can be found here includes some history of scripting and BASH as well
  • Types of text in scripts/li>
    • Plain (no quotes)
      echo hello
    • Semi-opaque (double quotes, expands variables)
      echo "hello $name"
    • Opaque (single quote, shows exactly what's in quotes)
       echo 'hello $name'
  • Important things to know
    • Backticks
      `this is an example of a backtick`
    • Shbang line
    • To run, file must be executable (it's not by default so you will need to change the file permissions There is a video example of me showing how to do that here)
    • To run you need to use the path of your script (unless in PATH)
    • It is important to TEST YOUR CODE
  • Sequence of a successful script
    • Test commands at command prompt
    • Create and edit the file in an editor (VIM)
    • Start script with shbang line ( such as: #!/bin/bash)
    • Add comment with function, name and date
    • Save
    • Change permissions
    • Test!!
    • Rinse and repeat

Suggested Activities and Discussion Topics:

  • Watch this video and follow along to create a shell script.

Would you like to see some more classes? Click here