para.sh - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
para.sh (625B)
---
1 #!/bin/sh
2 # Dependencies: POSIX sh, xargs
3 #
4 # Expects a TAB-separated list from stdin in the format:
5 # <url>[TAB[filename]]
6 #
7 # First parameter is a script which accepts these parameters.
8 # The passed script should return exitcode 255 on errors (to signal xargs).
9
10 jobs="4"
11 sep=" "
12 if test x"$1" = x""; then
13 echo "usage: $0 <script>" >&2
14 exit 1
15 fi
16
17 while read -r line; do
18 url=$(printf '%s' "$line" | cut -f 1 -d "$sep")
19 filename=$(printf '%s' "$line" | cut -s -f 2 -d "$sep")
20 test -n "$filename" && filename="$(basename "$url")"
21
22 printf '%s\0%s\0%s\0' "$id" "$url" "$filename"
23 done | \
24 xargs -t -0 -L 2 -P "$jobs" "$1"