Unlike previous assignments, this assignment should be completed by submitting scripts and output files. The scripts and output files should be uploaded to D2L individually and should use the names mentioned below.
Submit via D2L by 5:00 p.m. on Wednesday, March 16.
A set of files and directories is created with:
mkdir ex1; cd ex1
mkdir -p images jpg-{even,odd} png-{even,odd}
touch images/{1..10}.png images/{1..10}.jpg
Write a script the moves all of the even jpg files into
jpg-even
, all of the odd jpg files into
jpg-odd
, all of the even png files into
png-even
, and all of the odd png files into
png-odd
. Note that 1.jpg
is odd and
2.jpg
is even.
Provide the source code in file
move-images.sh
.
From within the ex1
directory execute your script
as follows:
ls -lR > ex1.txt
Both move-images.sh
and ex1.txt
should be submitted via D2L.
Write a shell script that sums the integers in a file. The first argument of the script is the name of the file. Be sure to print an error if the file argument is not provided.
First create an ex2
directory. Then enter that
directory and create the test file with:
(i=1;while (( i < 100 )); do echo $((i*3)); (( i++ )); done) > tst.dat
The script should accept one argument, the test file. If an incorrect number of arguments is supplied, the script should issue an error message and exit with a status of 1.
Assuming it is called appropriately, your script should output:
The sum is XXX.
Call your script, sum-of-ints.sh
.
Execute your script as follows:
sum-of-ints.sh tst.dat > ex2.txt
Both sum-of-ints.sh
and ex2.txt
should be submitted via D2L.
Write a shell script that outputs the second column of the file created with the script:
i=1;
while (( i < 10 )) ; do
echo $((i*3)),$((i*5)),$((i*7))
(( i++ ))
done > tst.dat
The script should accept one argument, the name of the input
file (tst.dat
).
If an incorrect number of arguments is supplied, the script
should issue an error message and exit with a status of 1. Call
your script second-col.sh
.
Execute your script as follows:
second-col.sh tst.dat > ex3.txt
Both second-col.sh
and ex3.txt
should be submitted via D2L.
Hint: use IFS=,
and read a b c
to
parse the columns.
Write a script that prompts a user for a password until the
password please
is entered. An example session
is:
password please:
password please:
password please:
thank you
In this case, please was entered at the third prompt. Note that the password should not be displayed. The program will only exit when the correct password is entered.
Call your script, please.sh
.