generated by powscript (https://github.com/coderofsalvation/powscript)

February 24, 2016 · View on GitHub

generated by powscript (https://github.com/coderofsalvation/powscript)

empty () { [[ "${#1}" == 0 ]] && return 0 || return 1 }

map () { local arr="$1"; shift; local func="$1"; shift; eval "for i in "${!arr[@]}\"; do func "$@" "$i" "${arr[\i]}"; done" }

pipemap () { func="$1"; shift; cat - | while read -r line; do func"func "@" "$line"; done }

application code

#!/usr/bin/env powscript shift lastinfo=""

if empty "$1"; then printf "%s\n\n%s" "Usage: m3ucheck <file.m3u>" "filters out broken links" exit fi

process_line(){ if [[ "$1" =~ ^(#) ]]; then lastinfo="$1" else testlink "$1" fi }

testlink(){ if curl --connect-timeout 2 --silent --head --fail "$1" &>/dev/null; then echo "lastinfo" echo "\1" fi }

cat "$1" | pipemap process_line