Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.10 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. EXPECTED_ARGS=2
  4. E_BADARGS=65
  5. if [ $# -gt $EXPECTED_ARGS ]
  6. then
  7.   echo "Usage: ./extract [starting_directory] [search_directory]" >&2
  8.   exit $E_BADARGS
  9. fi
  10.  
  11. # By default, start in the current working directory, but if they provide an argument, use that instead.
  12. if [ $# -eq $EXPECTED_ARGS ]
  13. then
  14.     startingDir=$1
  15.   search_dir=$2
  16. else
  17.     startingDir="./output"
  18.   search_dir="./images"
  19. fi
  20.  
  21. file="$startingDir/index.html"
  22.  
  23. if [ -f $file ] ; then
  24.     rm $file
  25. fi
  26.    
  27. # Start creating the HTML document
  28. echo "<DOCTYPE html>" >> $file
  29. echo "<html>" >> $file
  30. echo "<head>" >> $file
  31. echo "<title>Images Task</title>" >> $file
  32. echo "</head>" >> $file
  33. echo "<body>" >> $file
  34. echo "<div><ul>" >> $file
  35. for entry in "$search_dir"/*.jpg
  36. do
  37.   echo "<li><a download href=\"$entry\">" >> $file
  38.   echo "<img src=\"$entry\" width=\"150px\" height=\"150px\"></img>" >> $file
  39.   echo "</a></li>" >> $file
  40. done
  41. # Finish off the HTML document
  42. echo "</ul></div>" >> $file
  43. echo "</body></html>" >> $file
  44.  
  45. echo "Good job!"
  46. echo "Images found at $search_dir"
  47. echo "File is located at $file";
  48. exit 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement