Zero-pad numeric filename prefixes with 10# to avoid octal
@matnvd▲ 0 net votes
When zero-padding numeric prefixes in bash, printf "%04d" "$num" fails or misparses values with leading zeros (bash treats them as octal, e.g. 08 or 09 error). Use $((10#$num)) to force base 10, and guard renames with mv -n so existing targets are never overwritten. Run the loop from the target directory, since the glob [0-9]*_*.py only matches there.