The object of this assignment is to familiarize you with the vi editor and see some shell scripts in action.
Create two files that contain the shell scripts similar to those in examples 2.2 and example 2.7 in the book (pages 39-40 and 64). While you could just copy and paste the information from the web site, the information will stay with you longer if you type it yourself.
You will put the first script into a file named script1a.csh and the second script into a file named script1b.sh
#!/bin/csh -f
# The Party Program - Invitations to friends from the "guest" file
set guestfile = ./guests
if (! -e "$guestfile") then
echo "$guestfile:t non-existent"
exit 1
endif
setenv PLACE "Sarotini's"
@ Time = `date +%H` + 1
set food = ( cheese crackers shrimp drinks "hot dogs" sandwiches )
foreach person ( `cat $guestfile` )
if ( $person == root ) continue
cat << FINIS
Hi $person! Please join me at $PLACE for a party!
Meet me at $Time o'clock.
I'll bring the ice cream. Would you please bring $food[1] and
anything else you would like to eat? Let me know if you can
make it. Hope to see you soon.
Your pal,
ellie@`hostname`
FINIS
shift food
if ($#food == 0) then
set food = ( cheese crackers shrimp drinks \
"hot dogs" sandwiches )
endif
end
echo "Bye..."#!/bin/bash
# The Party Program - Invitations to friends from the "guest" file
guestfile=./guests
if [[ ! -e "$guestfile" ]]
then
echo "${guestfile##*/} non-existent"
exit 1
fi
export PLACE="Sarotini's"
(( Time=$(date +%l) + 1 ))
declare -a food=(cheese crackers shrimp drinks 'hot\ dogs' sandwiches )
declare -i n=0
for person in $(cat $guestfile)
do
if [[ $person == root ]]
then
continue
else
#start of here document
cat <<- FINIS
Hi $person! Please join me at $PLACE for a party!
Meet me at $Time o'clock.
I'll bring the ice cream. Would you please bring ${food[$n]} and
anything else you would like to eat? Let me know if you can
make it. Hope to see you soon.
Your pal,
ellie@`hostname`
FINIS
n=n+1
if (( ${#food[*]} == $n ))
then
n=0
fi
fi
done
echo "Bye..."Both scripts set a guestfile variable;
it should reference a file named
./guests. This is line three in all the
sample files.
You will have to create a file named guests
in the same directory where your script is.
It should contain three lines with
one name per line:
joe, sally, and your first name.
Be very careful to distinguish between apostrophes and backticks. ' is an apostrophe. ` is a backtick.
Be extremely careful with spaces. Adding a space or taking one out can cause your script to fail.
I have replaced all occurrences of printf
with echo.
Each file in the book has a line that looks like one of these:
mail -v -s "Party" $person << FINIS mail -v -s "Party" $person <<- FINIS
I have replaced the text mail -v -s "Party" $person with just
the word cat. The revised lines will look
like this:
cat << FINIS cat <<- FINIS
In the C shell script,
the line with just the word FINIS on it must have the
word beginning in column one; no leading tabs or spaces, and no extra
tabs or spaces after the word.
The bash script needs to have the construction
date +%H changed to
date +%l so that it will work properly.
That is the lowercase letter "L" after the percent sign, not
the digit one.
The bash script needs a backslash before the blank
in the word "hot\ dogs" in order to work properly.
Please add a comment line after the #! line that
gives your name. For example:
#!/bin/sh # written by Moishe Pipik
You will have two files named script1a.csh and script1b.sh. Use tar utility to package the two files into a single compressed, gzipped file (called a “tarball”). The tarball file will have your family name and first name separated by an underscore, followed by the assignment number. Thus:
tar cvzf eisenberg_david_1.tgz script1a.csh script1b.sh
Email the tarball file to the instructor.