On 05/22/2012 08:56 AM, David Haller wrote:
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"..
Confused yet?
Yes - thoroughly... Digesting the wisdom, it seems that there is a difference in how calc is treating stdin depending on whether it is called from within a while loop or otherwise. The bug/bag example was great exposing what calc was choking on. But I can't for the life of me see how calc can inherit stdin differently when called within a while loop or for loop. I see in the for loop there is no stdin to inherit -- I get that. I also see in the while loop that the potential is there due to redirecting gtkrc-file.txt to feed the while loop -- but that is where things cloud over and my eyes roll back in my head. Where the train wreck occurs in my mind is that regardless of while or for, the line is passed into variable 'l' which is parsed into 'rgb' and then into 'r', 'g' & 'b' --before-- being fed to calc. How does calc even know of a different stdin? Passing '