Nemo's bash challenge for the day

Nemo - earth native nemo at cheeky.house.cx
Fri Mar 29 11:31:26 EST 2002


Yay says I, and no further comment till
[a] I try and implement it, 
[b] Michael sees the rest of my TODO list. (ok, except the "learn Perl"
bit)

In other XDM related news... the questions regarding 
"why don't I just run `xrdb -merge` over the Xresources file and choose
a new theme from Xsetup?" 
... I have an answer :)

...It's basically as I said last night - XDM loads the Xresources file
as it currently exists, and uses that for the xlogin window. If the
Xsetup file changes the Xresources and xrdb -merge's it, then anything
loaded *after* that will respect those new Xresources - but XDM is
already loaded - so it does what I consider the "correct" behaviour - it
uses it's already-known resources. ("correct", but "fiddly" to work
around for themes ;)

Of course, since the xlogin window isn't actually mapped till *after*
the Xsetup script is finished, you could argue that the xlogin window
should respect the new -merge'd resources... 

As it stands, it's not something I think is too important.
(frankly, calling it a "workaround" at my end is overstating it. it'd be
alot more work to convince the Xfree86 coders to change it)

The only possible "downside" with the current scheme... is that if an
XDM theme manages to stop you from loggign into XDM for some reason
(either by exploiting a "real" bug in XDM - like making the login: box
too small), or by, say, crashing X somehow), then the system will never
choose a new theme automatically for you. I don't see this being a big
problem :)

While we're talking bash scripts... does anyone know an easier way of
doing this:

#!/bin/sh
basename `ls -o $1 | awk -F " "  '{ print $10}'`

(call it with $1 as a symbolic link, and it returns the name of the file
it's linked to)

.../Nemo






On Fri, Mar 29, 2002 at 10:14:17AM +1100, Michael Still did utter:
> 
> Well, I said it could be done...
> 
> The brief: Generate a random number, and then return that element from a
> list of elements, in bash
> 
> The code: (Assuming that the arguements on the command line are the
> possible return options, and that the random number generator is running
> as a separate script)
> 
> LOBOUND=0
> HIBOUND=$#
> shift $(( $LOBOUND + ($HIBOUND * $RANDOM) / (32767 + 1) ))
> echo $1
> 
> See the attachments for some exploratory scripts I wrote while coming up
> with this truncated sh. There are 54 lines of comments / white spaces, to
> the 4 or so lines of actual code.
> 
> Have a nice life...
> 
> Cheers,
> Mikal
> 
> PS: How good is the bash random? See the attachment output.count for a
> summary of 100,000 numbers between 1 and 10 being generated with the
> default seed. It's probably good enough for most people.
> 
> PPS: If you want the code, it should also be online at
> http://www.stillhq.com/cgi-bin/getpage?area=bashrand&page=index.htm in
> about 30 minutes, depending when Andrew goes to sleep.
> 
> -- 
> 
> Michael Still (mikal at stillhq.com)     UMT+11hrs



> 1: 9964
> 2: 10009
> 3: 9978
> 4: 10015
> 5: 9997
> 6: 10020
> 7: 10011
> 8: 10008
> 9: 10006
> 10: 9992





More information about the linux mailing list