View previous topic :: View next topic |
Author |
Message |
Dominique_71 Veteran
Joined: 17 Aug 2005 Posts: 1869 Location: Switzerland (Romandie)
|
Posted: Thu Apr 18, 2013 11:08 am Post subject: BASH: weird variable division [solved] |
|
|
Let's go bash. I try to debug fvwm-crystal xmms2 support.
First, I have
Code: | # xmms2 server config| grep \.volume
jack.volume.left = 100
jack.volume.right = 100 |
Code: | xmms2 server config |grep \.volume| sed -e "s;.*.volume.* = ;;" | sed -e "s;^.*$;AddToMenu /Music 'Volume: &' Popup /Mixer:;" |
give me
Code: | AddToMenu /Music 'Volume: 100' Popup /Mixer:
AddToMenu /Music 'Volume: 100' Popup /Mixer: |
which is what I want. But I need only 1 line of output. I made this:
Code: | j=1 ; for i in "$(xmms2 server config)" ;
do while [[ $j -lt 2 ]] ;
do echo $i | grep \.volume | sed -e "s;.*.volume.* = ;;" | sed -e "s;^.*$;AddToMenu /Music 'Volume: &' Popup /Mixer:;" ; j=$(($j+1)) ;
done ; done |
which give me
Code: | AddToMenu /Music 'Volume: 50' Popup /Mixer: |
Only 1 line is what I want, but the volume value is divided by 2
What is wrong with this, and what can I do? _________________ "Confirm You are a robot." - the singularity
Last edited by Dominique_71 on Thu Apr 18, 2013 2:01 pm; edited 1 time in total |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Thu Apr 18, 2013 12:22 pm Post subject: |
|
|
Dominique_71 ...
I don't have xmms installed, so I used a static file as input (with the output from xmms above):
Code: | % awk '/^jack\.volume.*/{a=$NF};END{print "AddToMenu /Music '\''Volume: "a"'\'' Popup /Mixer:"}' <(xmms2 server config)
AddToMenu /Music 'Volume: 100' Popup /Mixer: |
I'm not sure why you needed to itterate with a while loop as I assume you just want the value, anyhow the above is just what appeared to be the ready solution, if not then ping.
best ... khay |
|
Back to top |
|
|
ppurka Advocate
Joined: 26 Dec 2004 Posts: 3256
|
Posted: Thu Apr 18, 2013 12:28 pm Post subject: |
|
|
This works for me. Note the "q" at the end. I don't have xmms2, so I am just assuming some string as the input. Code: | ~» echo "jack.volume.left = 100
jack.volume.right = 100
xmms.something.some = 30
xmms.a.something = 200" | sed -n "/\.volume/{s/.*= \([0-9]\+\)$/AddToMenu \/Music 'Volume: \1' Popup \/Mixer:/p;q}"
AddToMenu /Music 'Volume: 100' Popup /Mixer:
~»
|
_________________ emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/ |
|
Back to top |
|
|
Dominique_71 Veteran
Joined: 17 Aug 2005 Posts: 1869 Location: Switzerland (Romandie)
|
Posted: Thu Apr 18, 2013 12:46 pm Post subject: |
|
|
Thank you both.
I was underestimating sed. I think ppurka's solution is the most appropriate in my case. It work fine at the shell, now I have to put it into fvwm and see what append with the special characters.
EDIT: One more quoting and a few more escape, and it work fine in fvwm _________________ "Confirm You are a robot." - the singularity |
|
Back to top |
|
|
|