#!/usr/bin/env bash brother_opts=() scanner_mode='Black & White' resolution='300' source='Automatic Document Feeder(left aligned)' duplex_source='Automatic Document Feeder(left aligned,Duplex)' device="brother5:bus4;dev3" valid_resolutions=("100" "150" "200" "300" "400" "600" "1200") current_page=$(find "$PWD" -name "out*.pdf" | sort | tail -n 1); read -r current_pageno <<<"${current_page//[^0-9]/ }" current_pageno=${current_pageno:-0} next_out_file="out$((current_pageno+1)).pdf" scan() { while getopts "dr:" flag; do case ${flag} in d) echo "Scanning duplex" source=$duplex_source ;; r) echo "Resolution=$OPTARG" if [[ ! " ${valid_resolutions[*]} " =~ [[:space:]]${OPTARG}[[:space:]] ]]; then echo "Resolution not supported" exit 1 fi ;; b) echo "Black and white"; ;; *) ;; esac done } case "$1" in scan) scan "${@:2}" exit 0 if [ "$2" = "duplex" ]; then true fi # cat <