Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- EXPECTED_ARGS=2
- E_BADARGS=65
- if [ $# -gt $EXPECTED_ARGS ]
- then
- echo "Usage: ./extract [starting_directory] [search_directory]" >&2
- exit $E_BADARGS
- fi
- # By default, start in the current working directory, but if they provide an argument, use that instead.
- if [ $# -eq $EXPECTED_ARGS ]
- then
- startingDir=$1
- search_dir=$2
- else
- startingDir="./output"
- search_dir="./images"
- fi
- file="$startingDir/index.html"
- if [ -f $file ] ; then
- rm $file
- fi
- # Start creating the HTML document
- echo "<DOCTYPE html>" >> $file
- echo "<html>" >> $file
- echo "<head>" >> $file
- echo "<title>Images Task</title>" >> $file
- echo "</head>" >> $file
- echo "<body>" >> $file
- echo "<div><ul>" >> $file
- for entry in "$search_dir"/*.jpg
- do
- echo "<li><a download href=\"$entry\">" >> $file
- echo "<img src=\"$entry\" width=\"150px\" height=\"150px\"></img>" >> $file
- echo "</a></li>" >> $file
- done
- # Finish off the HTML document
- echo "</ul></div>" >> $file
- echo "</body></html>" >> $file
- echo "Good job!"
- echo "Images found at $search_dir"
- echo "File is located at $file";
- exit 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement