start="2018-06-17" end="2018-07-01" min=`date -d "${start}" +%Y%m%d` max=`date -d "${end}" +%Y%m%d` [ -e /tmp/fd3 ] || mkfifo /tmp/fd3 exec 5<>/tmp/fd3 rm -rf /tmp/fd3 for ((i=1;i<=5;i++)) do echo >&5 done while [ $min -le $max ] do read -u5 date=${min} echo "date:" ${date} { sql=" select * from table where day = ${date} ;" echo "${sql}" hive -e "${sql}" > output_${date}.txt echo >&5 }& min=`date -d "1 day ${date}" +%Y%m%d` done wait exec 5<&- exec 5>&-