Re: bash increment in a given way

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

 





On 11 December 2010 14:34, S Mathias <smathias1972@xxxxxxxxx> wrote:
It's ok, that i can use this, when i want an incrementing sequence, in a given way:

# {START..END..INCREMENT}
$ for i in {0..10..2}; do echo "Welcome $i times"; done
Welcome 0 times
Welcome 2 times
Welcome 4 times
Welcome 6 times
Welcome 8 times
Welcome 10 times
$

but what's the "magic" for this? :

$ MAGIC; do echo "Welcome $i times"; done
Welcome 0 times
Welcome 1 times
Welcome 4 times
Welcome 5 times
Welcome 8 times
Welcome 9 times
$

All you need to do is work out the function behind the sequence. To generate this particular sequence, you need 2 loops, and outer one counting from 0..2 and an inner one counting between 0..1:

for n in {0..2};
do
ÂÂ for m in {0..1};
ÂÂ do
ÂÂÂÂÂ echo "Welcome $(((n * 4) + m)) times";
ÂÂ done;
done;

or, in one line:

for n in {0..2}; do for m in {0..1}; do echo "Welcome $(((n * 4) + m)) times"; done; done;

--
Sam
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
[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