If: ${onedate%%[!0]*} selects all 0 before the line $onedate .
we could remove these zeros by doing this (portable):
echo "${onedate#"${onedate%%[!0]*}"}"
In your case (bash only):
#!/bin/bash dates=( 01 02 02 08 10 18 20 21 0008 00101 ) for onedate in "${dates[@]}"; do echo -ne "${onedate}\t" echo "${onedate#"${onedate%%[!0]*}"}" done
It will be printed:
$ script.sh 01 1 02 2 02 2 08 8 10 10 18 18 20 20 21 21 0008 8 00101 101
user2350426
source share