CT320

Three headers follow: ! Long name of class !! Semester !!! New Chapter 2, replaced by the name of the current page.

CT320: Network and System Administration

Fall 2013

New Chapter 2

Links to the various pages for this class:

Wish I could do this: * Schedule

See this page as a slide show

CHAPTER 2: Scripting and the Shell

Linux Scripting

Linux Commands

Directory Navigation

File Related

Protection Related

Process Related

System Related

Linux Shells

Redirection

Pipes

Shell Features

Filter Commands

Shell Scripting

Shell scripts are programs that:

Input and Output

Variables and Quoting

Arguments

Script Syntax

if/then/else

    # Spaces count!
    if [[ $num -eq 1 ]]
    then
	echo "Number is one"
    elif [[ $num -eq 2 ]]
    then
	echo "Number is two"
    else
	echo "Number is $num"
    fi

Loops

    for datafile in *.zot
    do
        echo Now processing $datafile
    done

    for ((i=0; i<$max; i++))
    do
        echo $i
    done

Arithmetic

Variables are strings, force numeric evaluation with $((…)) or let a=2+2

    % alpha=1
    % beta=2             # no spaces around =
    % gamma=$alpha+$beta
    % let delta=alpha+beta
    % echo $gamma
    1+2
    % echo $delta
    3

Arrays

Somewhat limited capabilities compared to C:

    % array=(one two three)
    % echo ${array[1]}
    two
    % echo ${array[*]}
    one two three
    % echo ${#array[*]}
    3

Regular Expressions

Script Example

    #!/bin/bash
    # RunDiscrete - Script to optimize and run SAXS discrete scattering
    START=16384; STOP=8388608
    date > $1
    # Run original code
    time ./Discrete Data/1xib.pdb Data/1xib.int >>& $1
    for ((size=START; size<=STOP; size*=2))
    do
        # Create optimized code
        ./Mesa Discrete.cpp DiscreteMesa.cpp $size >> $1
        make # Compile optimized code
        # Run optimized code
        time (DiscreteMesa Data/1xib.pdb Data/1xib.int) >>& $1
    done

Resources

Modified: 2013-09-05T13:53

User: Guest

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building