diff --git a/multi-channel-bash-scripts/channeldown.sh b/multi-channel-bash-scripts/channeldown.sh index 5adfc9f..56a8515 100755 --- a/multi-channel-bash-scripts/channeldown.sh +++ b/multi-channel-bash-scripts/channeldown.sh @@ -72,19 +72,35 @@ if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then # Now that the prevchannel is stored in a var, loop through channels and find prev channel & increment for ((i = ${#CHANNEL_DIR_ARR[@]};i >= 1;i--)); do - + NEXT_CHANNEL_NUM=$i - if [[ ${i} == *"$PREV_CHANNEL"* ]]; then - echo "+++++ Found previous channel, incrementing by 1." - PREV_CHANNEL_FOUND=true - PREV_CHANNEL_DIR=${CHANNEL_DIR_ARR[i-1]} - continue + if [ "${i}" -gt 9 ]; then + + if [[ ${i} == *"$PREV_CHANNEL"* ]]; then + echo "+++++ Found previous channel, decreasing by 1." + PREV_CHANNEL_FOUND=true + PREV_CHANNEL_DIR="${CHANNEL_DIR_ARR[i-1]}" + continue + fi + + else + + if [[ "0"${i} == *"$PREV_CHANNEL"* ]]; then + echo "+++++ Found previous channel, decreasing by 1." + PREV_CHANNEL_FOUND=true + PREV_CHANNEL_DIR="${CHANNEL_DIR_ARR[i-1]}" + continue + fi + fi if [ "$PREV_CHANNEL_FOUND" = true ] ; then + + echo "PREV_CHANNEL_FOUND" + echo "$PREV_CHANNEL_FOUND" - NEXT_CHANNEL=${CHANNEL_DIR_ARR[i-1]} + NEXT_CHANNEL="${CHANNEL_DIR_ARR[i-1]}" break