logo © 1996 Phil Waclawski
Felitaur Site
Offerings
About Me
Crafts
Services
ftp files
Help Files
What's New?
Home Page
Other Links
Anatomy &
Physiology
Arthropods
Biology
Computers
Ferrets
Fun Links
Internet
Linux
S.C.A.
Win 95/NT
Comments or
Suggestions
webmaster@ felitaur.com
   
Week 10 for CIS126DL Linux OS Course
Lecture Overview Index | Linux SysAdmin Homepage
Overview
Intro to BASH scripting with a little AWK

The following commands/programs will be used/discussed this week:

bourne
bash
korn
cshell
perl
python
./
chmod a+x
' (backquote)
echo
awk -F '{print $1}'

Scripting Concepts

variables
getting input
directing output
Using Other programs
List of Operators
Control statements (if elif else fi)
Control statements (case $1 in.....esac)
Repetition Statements (while() and for() )
Functions (for modular program design
Using Command Line Arguments ($0-$10)

Example Script

#!/bin/bash
#Note, that first line often must be changed to fit your system
file=~/diary
      date >> $file
      echo "Hello `whoami`, what did you do today?"
      read today
      echo "$today" >> $file
      echo >> $file
      echo "-----------------------------------------------" >> $file
      echo >> $file
Example Script 2

#!/bin/bash
set -o xtrace
echo "Do you believe the world is a sphere in shape?"
echo "Please answer y or n"
read answer
if [ $answer = y -o $answer = Y ]; then
        echo "Congrats, you live in the modern world"

elif [ $answer = n -o $answer = N ]; then
        echo "Get your head out of the sand you silly luddite"
else
        echo "What part of "Please answer y or n" don't you understand?";
fi

Questions
Why do you need to know how to script?
What are elements of good program design?
Where can you put your scripts and have them work without use the ./ ?
Activities & Assignments

  1. Copy both scripts and get them to work.
  2. Read up on using awk and bash.
  3. Note you can practice most of this on mcunix, just change the first line and you have no admin powers.
Resources
Check out the various web page resources on the Linux System Administration home page.