How to loop through dates using Bash?

后端 未结 8 762
一整个雨季
一整个雨季 2020-12-02 06:22

I have such bash script:

array=( \'2015-01-01\', \'2015-01-02\' )

for i in \"${array[@]}\"
do
    python /home/user/executeJobs.py {i} &> /home/user/         


        
8条回答
  •  孤街浪徒
    2020-12-02 06:46

    Bash is best written by leveraging pipes(|). This should result in memory efficient and concurrent(faster) processing. I would write the following:

    seq 0 100 | xargs printf "20 Aug 2020 - %sdays\n" \
      | xargs -d '\n' -l date -d
    

    The following will print the date of 20 aug 2020 and print the dates of the 100 days before it.

    This oneliner can be made into a utility.

    #!/usr/bin/env bash
    
    # date-range template