Last active
April 17, 2018 06:30
-
-
Save nvjkmr/c6ca055064c1a88516352c43b7edabfb to your computer and use it in GitHub Desktop.
Bash script to download all the files from a given URI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# defaults | |
LINK=http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-spring-2008/lecture-notes/ | |
NUMBER=5 | |
FILE=lec$.pdf | |
throwErr() | |
{ | |
echo "Unknown Error Occurred!" | |
echo "Usage: ./sdm -n=<number_of_iterations> -l=<link_of_directory> -f=<file_name_pattern>" | |
exit 0 | |
} | |
for i in "$@" | |
do | |
case $i in | |
-l=*|--link=*) | |
LINK="${i#*=}" | |
shift | |
;; | |
-n=*|--number=*) | |
NUMBER="${i#*=}" | |
shift | |
;; | |
-f=*|--file=*) | |
FILE="${i#*=}" | |
shift | |
;; | |
-h|--help) | |
echo "Usage: ./sdm -n=<number_of_iterations> -l=<link_of_directory> -f=<file_name_pattern>" | |
shift | |
exit 0 | |
;; | |
--default) | |
DEFAULT=YES | |
shift | |
;; | |
*) | |
throwErr | |
;; | |
esac | |
done | |
while [ "$NUMBER" != 0 ] | |
do | |
FILENAME="${FILE//$/$NUMBER}" | |
wget "${LINK}${FILENAME}" | |
# echo "wget $LINK$FILENAME" | |
NUMBER=$[$NUMBER-1] | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment