# Get the number of avaialble cores (threads). function _core_count() { cat /proc/cpuinfo | grep ^processor | wc -l } # Parse integers from mixed string. function _parse_ints() { echo "${*}" | tr '\n' ' ' | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' | sed 's/ /\n/g' } # Function-wrapper to iterate with specified function with provided files. # By default Iterates on all non-hidden files and directories. # Usage: _iterate_targets [FILES] function _iterate_targets() { local IFS=$'\n' local foo="${1}" local targets=("${@:2}") local total=${#targets[@]} local count=0 local failed=0 # set dafult value to target all supported archives. if [[ "${targets}" = "" ]]; then targets=($(ls)) total=${#targets[@]} fi # iterate each target. for target in "${targets[@]}"; do # increment counter. ((count++)) # status info. local status="[${count}/${total}] ${target}" echo -e "${color_bwhite}${status}${color_default}" # Call function. ${foo} "${target}" # Show error. if [[ ${?} != 0 ]]; then ((failed++)) echo -e "${color_bred}${status}: Failed.${color_default}" fi done # Show error. if [[ ${failed} != 0 ]]; then echo -e "${color_bred}Failed: ${failed}.${color_default}" false fi }