Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Looping cURLy Braces

No, this article is not about my daughter’s curly hair and that expander thingie she had in her mouth for awhile (that sucked for her, booo). Instead we’re talking about expanding braces in shell scripts so we can expand braces in the script.

What’s a brace? As with grammar, a brace is a type of bracket meant to denote a series of characters. The bash interpreter will then allow for the expansion to include a series, such as 1..100 or 1 to 100 or a..z or a through z, useful in loops where the variable name (num in the below example) when invoked in the loop as $num will expand to be the number in the series in the loop. In the below example, we start with a set command and use -B to expand the curly braces:

set -B
for num in {1..100}; do
echo `curl -s -k 'GET' -H 'header info' 'http://krypted.com/log='$num`
echo 'http://krypted.com/log='$num
done


Note: In the above example, I did an echo just as a debugging line. I’d remove that before actually running the script (or more to the point automating it to run).

If we hadn’t of used the brace, we’d just be typing a lot more to get a 1 to 100 series to expand (e.g. for (( i = 0; i

A simpler example might be to use the following , which uses a series of letters instead:

set -B
for letter in {a..z}
do
echo $letter
done


If you actually wanted to learn more about palatal expanders then I’m sorry to bore you with everything else – here’s a better place for learning about that: https://en.wikipedia.org/wiki/Palatal_expansion

The post Looping cURLy Braces appeared first on krypted.com.



This post first appeared on Krypted.com | Tiny Deathstars Of Foulness, please read the originial post: here

Share the post

Looping cURLy Braces

×

Subscribe to Krypted.com | Tiny Deathstars Of Foulness

Get updates delivered right to your inbox!

Thank you for your subscription

×