David Haller wrote:
Hello,
On Tue, 22 May 2012, Anton Aylward wrote:
Anton Aylward said the following on 05/22/2012 08:53 AM:
David Haller said the following on 05/22/2012 06:17 AM:
The 'bg' (resp. 'bag') undefined was produced by _calc_ on the line _r=$(calc -p "255 * $r") on the first round. So, what happens? calc reads stdin after doing the "255 * $r" calculation, reading the next line of the gtkrc, i.e. the line bg[SELECTED] = { 0.216, 0.286, 0.431 } (or in my version: bag[SELECTED] = { 0.216, 0.286, 0.431 })!
Something is wrong here. The script should work if run from cron, from the console CLI, across a telnet/ssh session, as well as under an xterm from any GUI, never mind being invoked from another script or program or used as a library function.
Why is gtkrc being read in?
Because that's the whole point of the script. Oh, you mean by calc? Because calc 'inherits' the stdin from the while-loop.
Sorry, I worded that badly. I realise that the test file is gtkrc-test.txt, but didn't David try it with other files as well?
No, dcr tried it with a for-loop, where no stdin was "in the loop".
In the script though, he fed the while-loop-stdin from the gtkrc and that's the stdin calc read as well. And that's also why the 'echo .. | calc' works, as then calc's stdin is fed by echo and not from the while-loop i.e. the gtkrc.
Compare to similar problems using ssh, which even has the option '-n' for exactly that problem. Anyway: redirecting calc's stdin from /dev/null works, as calc then does _not_ read the while-loop-stdin i.e. the gtkrc and barf's on the next line "up", which happens to be the second 'bg[' line (or bag in my modified version). Again: I changed the first uncommented lines that calc get fed in the gtkrc to read:
{ bug[NORMAL] = { 0.125, 0.129, 0.149 } bag[SELECTED] = { 0.216, 0.286, 0.431 } bg[INSENSITIVE] = { 0.125, 0.129, 0.149 }
So, what happens? dcr's script reads the file up to 'bug', parses that to the variables $r, $g, $b and then calls
_r=$(calc -p "255 * $r")
Where is stdin of the loop at this point? The line 'bug[...' was read, nextup in stdin is 'bag[...]'. And that's what calc reads, tries to evaluate and thus "barfs" "'bag' undefined"..
barf bag? Is programming getting that bad these days? :-)
Confused yet?
HTH, -dnh
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org