Re: script to loop through dates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



olivares33561 via users wrote:
> Dear Will, thanks for your help.  I was able to do it. 
> The following does the job!
> ------
> #!/bin/bash
> start=$1
> end=$2
> 
> start=$(date -d $(echo $start | sed 's/\./-/g') +%Y%m%d)
> end=$(date -d $(echo $end | sed 's/\./-/g') +%Y%m%d)

This is a minor improvememnt, but you can eliminate the call
to sed and use parameter expansion.  Instead of:

    echo $start | sed 's/\./-/g'

use:

    echo ${start//./-}

In a small script it won't make a huge difference in speed,
but if you do something which uses a large number of loop
iterations it can be noticeable.

If nothing else, it is a good bit shorter.

> date -d"$start" +%Y.%m.%d
> 
> while [[ $start -lt $end ]]

Also not hugely important here, or at the root of your
question, you can use `((` rather than `[[` to simplify the
arithmetic evalution, i.e.:

    while (( start < end ))

(You can use or not use `$` before the variable within
bash's arithmetic evalution context.)

-- 
Todd

Attachment: signature.asc
Description: PGP signature

-- 
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux