类似 Python 的 __file__
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
Using ${BASH_SOURCE[0]} instead of $0 produces the same behavior regardless of whether the script is invoked as <name> or source <name>.
ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
xargs
cat ids.txt| sed 's#\(\w\+\)#\1.png#'| xargs -P 40 -n 1 -I {} wget -q -c http://example.com/{} -U 'Mozilla/5.0 (Linux; U; Android 2.1)'
parallel
cat ids.txt| sed 's#\(\w\+\)#\1.png#'| parallel -j4 "wget -q -c http://example.com/{} -U 'Mozilla/5.0 (Linux; U; Android 2.1)'"
还可以通过 FIFO 文件控制进程数量
awk '!visited[$0]++' your_file > deduplicated_file
ref: How to remove duplicate lines from files preserving their order