In attempting to rename a set of files with variations of (1-26), Left/Right and png/bmp I have the following script
#!/bin/bash
NUMBER_LIST=$(seq -f "%03g" 1 26)
EXT_LIST=("png" "bmp")
SIDE_LIST=("right" "left")
for NUMBER in $NUMBER_LIST
do
for SIDE in $SIDE_LIST
do
for EXT in $EXT_LIST
do
OLD="${SIDE}_${NUMBER}.${EXT}"
NEW="${NUMBER}_${SIDE}.${EXT}"
mv $OLD $NEW
done
done
done
Only files that are designated right and bmp get renamed. So it looks like it is only iterating through the outermost loop, and not iterating through the inner loops (just uses first element).
I've looked elsewhere on the net but am having trouble finding anything relevant.
Any guesses as to what might be wrong?
Thanks, Jeff
$NUMBER_LIST), so you must base your loops on arrays, e.g.,for SIDE in "${SIDE_LIST[@]}". Additionally, I suggest not using all-uppercase variable names. Referencing an array variable as if it were a scalar - e.g.,$SIDE_LIST- implicitly returns the array element with index0, so you're looping over 1 value only.$SIDE_LISTis a scalar reference, whereas"${SIDE_LIST[@]}"returns the entire array.