User Tools

Site Tools


Sidebar

projects

wcp1 (due 20240124)
pct0 (bonus; due 20240125)
pct1 (bonus; due 20240125)
abc0 (due 20240131)
pct2 (due 20240131)
wcp2 (due 20240131)
dac0 (due 20240207)
pct3 (bonus; due 20240207)
wcp3 (due 20240207)
gtf0 (due 20240214)
pct4 (due 20240214)
wcp4 (due 20240214)
bwp1 (bonus; due 20240228)
pct5 (bonus; due 20240228)
usr0 (due 20240228)
wcp5 (due 20240228)
gfo0 (due 20240306)
pct6 (due 20240306)
tpb0 (due 20240306)
wcp6 (due 20240306)
pct7 (bonus; due 20240313)
tpb1 (due 20240313)
wcp7 (due 20240313)
pct8 (due 20240320)
tpb2 (due 20240320)
wcp8 (due 20240320)
pct9 (bonus; due 20240327)
wcp9 (due 20240327)
bwp2 (bonus; due 20240410)
fwg0 (due 20240410)
gfo1 (due 20240410)
pctA (due 20240410)
wcpA (due 20240410)
wpa0 (due 20240410)
pctB (bonus; due 20240417)
upf0 (due 20240417)
wcpB (due 20240417)
ldg0 (due 20240424)
pctC (due 20240424)
wcpC (due 20240424)
pctD (bonus; due 20240501)
wcpD (bonus; due 20240501)
gfo2 (due 20240508)
pctE (bonus; due 20240508)
wcpE (bonus; due 20240508)
EoCE (due 20240516)
haas:spring2024:unix:cs:csc


Corning Community College


UNIX/Linux Fundamentals



EoCE alternate question activity: Analyzing Shell Script Logic

~~TOC~~

Objective

To gain additional familiarity with shell scripting.

Background

Shell scripting enables you countless possibilities for automating tasks, both menial and sophisticated in nature.

However, like any new tool or concept, one needs to spend time with, and play with things, to get a better understanding.

Exploration

Analyze, poke at, and get running the following script on Lab46:

#!/bin/bash
 
month="`date +%m`"
year="`date +%Y`"
day="`date +%d`"
 
today="${year}${month}${day}"
csem=""
for item in `wget -q -O - http://www.corning-cc.edu/future/acacalendar/ \
        | grep 'Semester begins' | sed 's/\.\.*/:/g' \
        | sed 's/<[/a-z0-9]*>//g' | sed 's/:Semester begins : /:/g' \
        | sed 's/:First Summer Session begins : /:/g' \
        | egrep -o '[FWS][a-z]* [0-9]{4} S[a-z]*:[A-Z][a-z]* [1-9][0-9]?' \
        | tr 'WSF' 'wsf' | sed 's/ \([1-9][0-9][0-9][0-9]\) semester/\1/g' \
        | sed 's/ /*/g'`; do
    sm="`echo $item | cut -d':' -f1`"
    out=$(date --date "`echo $item \
        | sed 's/^[a-z]*\([0-9]*\):\([A-Za-z]*\)\*\([0-9]*\)$/\2 \3 \1/'`" \
        +%Y%m%d)
 
    if [ "$today" -ge "$out" ]; then
        csem="$sm"
    fi  
done
echo "$csem"
 
if [ -z "$csem" ]; then
    status=1
else
    status=0
fi
 
exit $status

Questions

  1. What is the purpose of this script?
  2. What is the general flow of operations that takes place in this script?
  3. Explain what today=“${year}${month}${day}“ does.
  4. What does sed 's/<[/a-z0-9]*>//g' appear to do?
  5. What are the raw $item values being iterated in the for loop?
  6. What is the purpose of the if statement?
  7. Any potential bugs that could effect proper operation?
  8. What is the significance of exiting with a value of 0 vs. that of 1?
haas/spring2024/unix/cs/csc.txt · Last modified: 2013/04/22 17:01 by 127.0.0.1