From 3561f6811eab6965acd0e2d4d95ea8771e223c51 Mon Sep 17 00:00:00 2001 From: Justin Emter Date: Wed, 17 Jan 2018 09:40:59 -0800 Subject: [PATCH] Fixed channeldown.sh to work with double digit dirs. --- multi-channel-bash-scripts/channeldown.sh | 30 +++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) 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