surfrock66
surfrock66

Reputation: 79

Bash For Loop: Decrementing starting from a variable

I've done some searching and this looks like it should work, and it isn't, and I'm stumped.

I'm on a CentOS box and want to basically shift all backups 1 folder up, to a limit of like 60 backups, and that limit is set in a variable $BKPLIMIT.

for (( i=$BKPLIMIT; i==0; i-- )); do
    j=$(($i-1))
    if [ -d "backup.$j" ]; then
        echo "$i $j backup.$i backup.$j"
        #mv "backup.$j" "backup.$i"
    fi
done

It looks, from my debugging, the script is not entering the loop. I is stumped :( I've also tried doing "$(seq $BKPLIMIT 0) which didn't work.

Upvotes: 0

Views: 4187

Answers (1)

William Pursell
William Pursell

Reputation: 212248

Change i==0 to i>0 or i!=0. The loop condition must be true for the loop to be executed.

Upvotes: 4

Related Questions