0

I am new to bash scripting and trying to write a loop to run a curl command but however getting errors. Please suggest the write syntax.

    #!/usr/bin/env sh
    start = $1
    end = $2
    
    start=$(date -d $start +%Y-%m-%d)
    end=$(date -d $end +%Y-%m-%d)
    
    while [[ $start -le $end ]]
    do
        echo $start
        curl -H "command, which can't be shared"
        start=$(date -d"$start + 1 day" +"%Y-%m-%d")
    done

The command line to run the script used sh filename.sh "2022-02-01" "2022-02-25".

However, the first error I received is windows cannot find '2022-02-01'. Make sure you typed the name correctly, and then try again.

Please suggest the errors.

  • Problem is *`spaces`* arround `=` equal sign. – F. Hauri - Give Up GitHub Mar 29 '22 at 15:41
  • Also, `[[ -le ]]` compares integers, not dates; it'd be better to convert the dates to seconds-since-epoch format to convert them. And `[[ ]]` is a bash extension (technically a ksh extension that bash copied); if you want to use it in a script, use a bash shebang (i.e.. `#!/usr/bin/env bash` or `#!/bin/bash`) instead of plain sh. – Gordon Davisson Mar 29 '22 at 17:27

0 Answers0