Personal info for wayward

Name: Zoran Rilak

Notes: Linux/*NIX developer. Computer Science undergraduate. Currently at work in Percepts & Concepts Lab at psychology dept., Indiana University. Interested in cognitive sciences.

Recent diary entries for wayward:
RSS

4 Aug 2005 (updated 4 Aug 2005)  »

bash-ing it out, part #2

Upon further inspecting the matter, I've discovered a nifty little program called seq. While I'm not certaing that it's a part of coreutils, most likeyly any decent distro will have it. seq does the neat trick of multiple downloading, like so:

$ foreach i in `seq -w 1 19`; do get --continue http://where.from/what$i.pdf; done

For the sake of symmetry, though, I would prefer to have one simple bash function doing this for me, because it is in the spirit of any good programmer to keep things simple and write them in their own scripting language whenever possible. :)

27 May 2005 (updated 27 May 2005)  »

bash-ing it out, part #1: embrace the braces

Tonight I set out to find the most plausible way of downloading many similarly named files at once. Suppose we want to wget a series of articles named

article_1.pdf
article_2.pdf
...
article_38.pdf

No doubt everybody needed to deal with this situation at some time or another. Perhaps the simplest reasonable solution is to iterate using bash's builtin arithmetic expansion; so it would go something like this:

n=0
while [ $((n++)) -le 38 ]; do
# quotes mark the end of variable
wget http://server/dir/article_$n"."pdf
done

This, however, seems like a lot of typing, and not something you'd prefer to use if you wanted to download a small series of, say, 10-15 files -- writing and debugging bash scripts can get pretty ugly pretty soon.

There's a much nicer way to get there. If you know how brace expansion works, you might already know it. Brace expansion lets you specify a list of values for some part of the string and bash will expand it into a list of strings each containing one different item from the braced list in its proper place:

bash$ chmod -R g+rx ~/common/{gppp,gabel,timid}/doc

This will grant members of our group with read and execute permissions to the doc/ directory of gppp/, gabel/ and timid/ subdirectories under ~/common/. Note that in order for brace expansion to work, elements within the braces must not be prefixed nor postfixed with whitespaces, or bash will abandon brace expansion and just spurt it all out like an ordinary string.

There's another way to expand with braces and it does the trick with multiple downloads. You can use syntax {m..n} to expand to either a series of integers between and including n and m, given they are proper integers, or to a series of character constants in alphabetical order if m and n are characters, or will not expand at all if m and n are either of different type or neither integers nor characters. So now we can easily download our papers with a command such as

bash$ wget http://server/dir/article_{1..38}.pdf

This method, however, has its limitations. If you try to get bash produce a series of numbers zero-filled from the left, it wouldn't work:

bash$ echo {00..09}

yields a list of plain one-digit numbers. A workaround which I'm working on and will publish it here when done consists of a small shell function which takes two numeric arguments, optinally zero-filled from the left, and returns a comma-separated, brace-ready list. That will give us a good chance to discuss some more obscure bash issues such as arrays and IFS shell variable.

25 May 2005 (updated 25 May 2005)  »

First day at work.

Doing what needs to be done, I naturally had to solve some problems which kept popping up at varying levels of depth. For instance, setting up Eclipse on my Linux box turned out to be a non-straightforward task. First off, the Eclipse guys thought it to be a natural thing that one and only one user at any given time will be wanting to run Eclipse, so they employed the stupidest possible application model: Eclipse is to be unpacked and run from one directory. There is not a trace of multi-user philosophy in it, down to the very configuration files which reside under $ECLIPSE/configuration directory. Setting out to coax Eclipse into multiuserability (just for the sake of it), I created a group "eclipse", added myself to it, innocently chgrp'ed eclipse and chmod'ed g+s ./eclipse executable, and tried to run it. No go. Eclipse was written using GTK+ and, as I oh so well know, GTK+ refuses to enter its main loop if it detects that it's running with S?ID. Okay, second try; make a launcher:

#!/bin/sh
# /usr/local/bin/eclipse
cd /usr/local/eclipse
sg eclipse -c ./eclipse

This did the trick, with an additional chgrp -R eclipse /usr/local/eclipse to allow users to modify Eclipse's configuration and plugins directory. Alas, another caveat was soon to follow. When run like this, Eclipse failed to see my $PATH. I tried every possible invocation of sg, right down to sg - eclipse -c "bash -l -c ./eclipse", to no avail. Hmmm... Maybe the top #!/bin/sh masked my environment? Must check into this. Anyway, after I hardcoded the browser inside Eclipse to /usr/bin/epiphany and symlinked $ECLIPSE/jre -> my Java directory, everything worked like a charm.

Others have certified this person as follows:

[ Certification disabled because you're not logged in. ]

[ Home | Articles | Account | People | Projects ]