Thursday, March 31, 2016

Bash Dynamic Loops -- Read file daemon

#!/bin/bash 

COND1="break"
COND2="sleep 1"
 ## Dynamically change the loop logic from continue reading, to read 
 ## all data and break. 
[[ -z "${1}" ]] && COND="${COND1}" || COND="${COND2}" 
while IFS= read -d $'\n' -r a || ${COND}; do 
 [[ -n "$a" ]] && echo "curl -s http://foo.bar/some.php?id=${a}"
done < id_list.txt

exit 0 

No comments:

Post a Comment