shell script set the default numbers as double digit zero as prefix
0
votes
2
answers
2071
views
In a shell script, I'm processing, some addition process will print an output. If it is a single-digit one, then it has to add zero as a prefix.
Here is my current script:
c_year=2020
for i in {01..11}
do
n_year=2020
echo 'Next Year:'$n_year
if [[ $i == 11 ]]
then n_month=12
echo 'Next Month:'$n_month
else
n_month=$(($i + 1))
echo 'Next Month:'$n_month
fi
echo $date" : Processing data '$c_year-$i-01 00:00:00' and '$n_year-$n_month-01 00:00:00'"
done
The i
value is in doule digit, but the n_month
is still printing single digit. How do I set default shell output should return as double digit?
Or any alternate way to solve this?
Asked by TheDataGuy
(405 rep)
Nov 9, 2020, 01:04 PM
Last activity: Nov 2, 2022, 12:42 PM
Last activity: Nov 2, 2022, 12:42 PM