Three Four Easy Scripts

  1. Mere aggregation:
    Collecting output from separate utilities

    disk_info shell script (source) (OUTPUT)

    1. simple commands

      • can be on same line, separated by “;”

    2. for loop

      • loop variable

      • simple list of values for loop variable

    3. variable substitution: $d

      • shell replaces a placeholder with a value or result

    4. command substitution

      • for p in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
      • `seq 1 15` or $(seq 1 15)

      • utility program "seq" provides list values 1 to 15

      • provides a value for variable $lbl

      • often used to provide command arguments

  2. Simplify an interface
    ps2booklet shell script (source)  (OUTPUT)

    1. problem: creating a booklet document (“imposition”)

    2. psutils package provides tools

      • psbook — re-order pages

    1. commands are very simple

    1. syntax of <layout> is very difficult to work with

    1. simple if / then

      • test, aka [

    2. case

    3. installation: provide several names for one script

  1. Custom utility program
    tok(ens) Perl script (source)

    1. Example: extract image file names from an HTML file:

      • $ egrep '<img[^>]+src="([^"]+)"' EM-0029-01.html  (OUTPUT)

      • $ egrep -o '<img[^>]+src="([^"]+)"' EM-0029-01.html (OUTPUT)
        <img src="/Images/topskip.gif" ...

      • $ tok '<img[^>]+src="([^"]+)"' EM-0029-01.html
        /Images/topskip.gif

    2. “Shebang” tells system how to execute this file (which program will interpret the text)

    3. Advantages:

      • More powerful and convenient language syntax

      • Better performance

    4. Disadvantages:

      • Less portable (requires interpreter and libraries installed)

  2. Output munging
    dur Perl script (source) (OUTPUT)  (DIAGRAM)

    1. sndfile-info output is too verbose and not in convenient format.

    2. Quoting filenames
    3. Starting the child process
    4. Scanning the output
    5. Printing the results