Dynamic Range in Bash

$(eval "echo {${min}..${max}}")

0
By: bbates
2014-02-22 14:24:48

These Might Interest You

  • You can get what functions at which addresses are inside a dynamic link library by this tool.


    2
    nm --dynamic <libfile.so>
    Vereb · 2009-09-13 09:27:57 0
  • Simple one-liner for scanning a range of hosts, you can also scan a range of ports with Netcat by ex.: nc -v -n -z -w 1 192.168.0.1 21-443 Useful when Nmap is not available:) Range declaration like X..X "for i in {21..29}" is only works with bash 3.0+ Show Sample Output


    9
    for i in {21..29}; do nc -v -n -z -w 1 192.168.0.$i 443; done
    rez0r · 2009-09-25 03:31:29 3
  • Useful for grepping an IP range from the maillog. When for instance dealing with a spam-run from a specific IP range, or when errors occur from or to a specific IP-range. In the example above the IP range 183.0.0.0/10 (183.0.0.0 - 183.63.255.255) To grep the IP range 124.217.224.0/19 (124.217.224.0 - 124.217.255.255) from the maillog: egrep '124\.217\.2(2[4-9]|[34][0-9]|5[0-5])' -J /var/log/maillog* NOTE: the location of the maillog may vary based upon operating system and distribution.


    0
    egrep '183\.([0-9]|(1[0-6]|2[0-3]))' -J /var/log/maillog*
    wazigster · 2010-10-17 21:44:57 0
  • Since Bash doesn't support two-dimensional arrays, you can limit your columns length by some big enough constant value ( in this example 100 ) and then index the array with i and j, or maybe write your own get() and set() methods to index the array properly like I implemented for example ( see Sample output ). For example for i=0 and j=0...99 you'll pick up one of 100 elements in the range [0,99] in the one-dimensional array. For i=1 and j=0...99 you'll pick up one of 100 elements in the range [100,199]. And so on. Be careful when using this, and remember that in fact you are always using one-dimensional array. Show Sample Output


    9
    arr[i*100+j]="whatever"
    RanyAlbeg · 2011-02-18 00:47:25 2

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: