date is a command. Run it from the command line and see if it exists. If not, install it.
Next, try my suggestion
sh -x and see what ${i} expands to. If $i for example is "050708", run the command on the command line and see what it does. Take care about quoting, that is likely to go wrong
Debugging is
looking at what your program does differently as expected, and if you don't understand experiment step by step until you find out why.
Also, pay attention to what UnSpawn said about generating valid dates. Your script won't do that, as after 0531 you will calculate 0532, 0533, while you want 0601, 0602. UnSpawn's suggestion is to let 'date' do the calculation by adding an offset in days in the -d string.
Take a look at this modified script. I went thru seconds instead of days.
Code:
#! /bin/bash
echo "enter Swath number"
read s
echo "please enter first date and MMDD press ENTER"
read i
echo "please enter last date and MMDD press ENTER"
read j
i_ts=$(date -d 08${i} +%s)
j_ts=$(date -d 08${j} +%s)
for((i_ts=$i_ts; i_ts <= j_ts; i_ts=(($i_ts+86400)) ))
do
ds="1970-01-01 $i_ts sec"
date=$(date -d "$ds" +%y%m%d )
echo "i_ts: $i_ts, j_ts: $j_ts, i: $date"
done
The output is this, and comes close to what you need.
Code:
donald_pc:/tmp$ ./t.sh
donald_pc:/tmp$ ./t.sh
enter Swath number
44
please enter first date and MMDD press ENTER
0529
please enter last date and MMDD press ENTER
0602
i_ts: 1212033600, j_ts: 1212379200, fdate: 080529
i_ts: 1212120000, j_ts: 1212379200, fdate: 080530
i_ts: 1212206400, j_ts: 1212379200, fdate: 080531
i_ts: 1212292800, j_ts: 1212379200, fdate: 080601
i_ts: 1212379200, j_ts: 1212379200, fdate: 080602
donald_pc:/tmp$
jlinkels