Hello, On Mon, 21 May 2012, David C. Rankin wrote:
Here is one I don't understand. I needed a simple script to part gtkrc and convert the r,g,b (0.0-1.0) values to (0-255). So I decided to use 'calc' to get the floating point values. The script was:
#!/bin/bash
while read l; do [[ $l =~ , ]] && [[ ${l:0:1} != [#] ]] && { rgb=${l##*[{] } rgb=${rgb%\ \}*} rgb=${rgb//,} r=${rgb%% *} g=${rgb% *} g=${g#* } b=${rgb##* } _r=$(calc -p "255 * $r") _g=$(calc -p "255 * $g") _b=$(calc -p "255 * $b") echo "${rgb} => r:$r g:$g b:$b => r:$_r g:$_g b:$_b"; } done < gtkrc-file.txt
The sample gtkrc file is included at the end of the message. Running the script resulted in the error:
15:38 providence:~/cnf/kde3> sh parsegtkrc.sh "bg" is undefined [..] Huh? It worked, but only for the first value and threw a "bg" is undefined error?? [..] style "default" { bg[NORMAL] = { 0.125, 0.129, 0.149 } bg[SELECTED] = { 0.216, 0.286, 0.431 } bg[INSENSITIVE] = { 0.125, 0.129, 0.149 }
I tried using bash -vx on the script. I got suspicious. I changed the first 2 bg into bug and bag respectively. Enlightenment came using strace -f -eprocess,write bash parsegtkrc.sh 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 })! Your script works if you use: _r=$(calc -p "255 * $r" < /dev/null) _g=$(calc -p "255 * $g" < /dev/null) _b=$(calc -p "255 * $b" < /dev/null) HTH, -dnh -- Warning: Pregnancy can cause birth -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org