e8fbbfa367c6a1c3cfef6cf68ca7cf580867a78d
   1#! /bin/bash
   2
   3# get a list of urls and corresponding output file names, then parse them to wget
   4
   5args=("$@")
   6list=${args[0]}
   7
   8if [[ $list == "" ]]
   9        then
  10                printf  "\n\x1b[31mWrong number of arguments\x1b[0m\n\n"
  11                printf "Usage: nameget LIST [DESTINATION] [ARGS]\n       where LIST is a text file of format [url] [name] (one pair per line)\n             [DESTINATION] is a path appended to the start of each [name] in LIST\n             [ARGS] is passed directly to wget"
  12                exit 1
  13fi
  14
  15if [[ -d ${args[1]} ]]; then                                    # check if args[2] is [DESTINATION] or [ARGS]
  16        outdir=${args[1]}
  17        if [[ ! $outdir =~ /$ ]]; then                  # check if [DESTINATION] has a trailing /
  18            outdir=$outdir/
  19        fi
  20        shift 2
  21else
  22        shift 1
  23fi
  24
  25otherargs=$@                                                                                                    # set aside remaining arguments for passing to wget
  26
  27while read -r url filename tail; do
  28  wget --cut-dirs=100 -r -np -nc --accept -e robots=off -O "$outdir$filename" "$url" $otherargs
  29done < $list