wget https://courses.cs.washington.edu/courses/cse391/24au/lectures/9/questions9.zip
unzip questions9.zip
-
Suppose I have a
bash
script namedscript1.sh
with the following contents#!/bin/bash book="Educated" echo "$book is a fantastic book" echo 'you should totally read $book' echo "hunter highly recommends $BOOK"
What would be the result of running
./script1.sh
(You may assume that it has execute permissions)? -
Write a shell script named
if_args.sh
which takes two command line arguments and prints “these are sum lucky numbers!” if their sum is equal to 7, and prints a sad face otherwise. -
Write a shell script named
loop.sh
that loops over all files in the current directory and prints out the contents of the file, with newlines between each output. (Note, we could probably do this without a loop, but for the sake of learning let’s use a loop here). For the sake of this problem you can assume there are no sub-directories in the current directory. If you finish early, try make this work when there are sub-directories. -
Write a shell script named
filter.sh
which takes any amount of numbers as arguments and prints out all the numbers which are even (Note that bash has a%
operator just like Java). If no numbers are given as inputs, print out a help message describing how to use the program. -
Write a shell script named
traveler.sh
which goes into each directory (only one deep) from the current directory and prints out it’s contents.