Skip to content

darkn3rd/script-tut

Repository files navigation

Scripting Tutorial

© Joaquin Menchaca, 2014

Overview

This is a basic tutorial of scripting modeled after typical tasks one would do with POSIX Shell Programming for system administration chores.

This tutorial will cover the basics of programming in a variety of languages, so it may be useful as a beginner's guide to scripting and as a reference. The target languages cover popular (either historical or current) scripting languages found on Linux/Unix and Windows oriented operating systems.

ScriptingBox Install Guide

I created a cumulative installation guide to get all the tools needed for this tutorial for Windows and Mac OS X:

Languages

These are the languages supported.

  • General Languages:
    • 📜 AWK
    • ☕ Groovy ††
    • 🐫 Perl
    • 🐘 PHP
    • 🐍 Python
    • 💎 Ruby
    • 📜 TCL (Tool Command Language)
  • Shell Languages:
    • 🐚 Bourne Again Shell (bash) †
    • 🐚 C Shell (csh) †
    • 🐚 Korn Shell (ksh) †
    • 🐚 Shell, POSIX (sh) †
  • Windows Languages:
    • 📜 Command Shell (BATCH)
    • 📜 JScript (WSH)
    • 📜 PowerShell †††
    • 📜 VBScript (WSH)

† Utilities available with either POSIX Utilities or GNU Core-Utils may be used.

†† Requires JVM (Java Virtual Machine) environment to run.

††† Requires CLR (Common Language Runtime) environment to run.

The Lessons

These are the overall plan for 14 topics and about 47 lessons (varies per language support for functionality):

Part I

This covers the basics of input/output, logic flow, variables, and data structures (arrays, associative arrays).

  • 📚 Output
    • 📗 Standard Output [A00]
    • 📗 Standard Error [A10]
    • 📗 Here Document (Multiline Output) [A20]
  • 📚 Variables
    • 📗 String Concatenation [B00]
    • 📗 Variable Interpolation [B10]
    • 📗 Formatting [B20]
    • 📗 Here String (Multiline String) [B30]
  • 📚 Arithmetic
    • 📗 Basic Arithmetic [C00]
    • 📗 Boolean Logic [C10]
    • 📗 Exponential [C20]
    • 📗 Math Function [C30]
  • 📚 Input
    • 📗 Reading a Line [D00]
    • 📗 Reading a Single Character [D10]
  • 📚 Branching
    • 📗 Branch on String [E00]
    • 📗 Ternary [E10]
    • 📗 Branch on Number Range [E20]
    • 📗 Branch on Number [E30]
    • 📗 Multiway Branch on Number [E40]
    • 📗 Multiway Branch on String Pattern [E50]
    • 📗 Branch on String Pattern [E60]
  • 📚 Looping
    • 📗 Collection Loop [F00]
    • 📗 Count Loop [F10]
    • 📗 Conditional Loop [F20]
    • 📗 Spin Loop [F30]
    • 📗 Skipping [F40]
  • 📚 Arrays
    • 📗 Assign by Index and Length [G00]
    • 📗 Assign by List and Enumeration by Item [G10]
    • 📗 Assign by List and Enumeration by Index [G20]
  • 📚 Associative Arrays
    • 📗 Assign by Key [H00]
    • 📗 Assign by List and Appending [H10]

Part II

This covers sub-routines and functions, passing values (parameters), and retrieving data. This also covers parsing command line arguments.

  • 📚 Sub-Routines
    • 📗 Creation and Calling [I00]
    • 📗 Global Variable (Scope) [I10]
    • 📗 Local Variable (Scope) [I20]
  • 📚 Arguments from the Command Line
    • 📗 Usage Statement (Script Name and Arg Count) [J00]
    • 📗 Enumerate Arguments in Order [J00]
    • 📗 Enumerate Arguments in Reverse Order [J10]
  • 📚 Parameters
    • 📗 Pass a Single Parameters [K00]
    • 📗 Pass Variable Number of Parameters [K10]
  • 📚 Exit
    • 📗 Returning an Exit Status Code [L00]
  • 📚 Functions [M00]
    • 📗 Return an Integer [M00]
    • 📗 Return a String [M10]
    • 📗 Return an Array [M20]

Part III

This section is under development, and may be put into another advance scripting section. As such, material is being developed for it. Areas important for basic system administration chores will be configuring environment variables, and having more advance command line argument processing with options and flags.

  • 📚 Environment Variables
    • 📗 Enumerating Variables [N00]
    • 📗 Enumerating Paths [N10]
    • 📗 Augmenting Variables [N20]
    • 📗 Exporting Variables [N30]
  • 📚 Options [O00]
    • 📗 Flags [O00]
    • 📗 Options [O10]
    • 📗 Long Form [O20]

About

Tutorials on Basic Scripting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published