Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
BASH: weird variable division [solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Dominique_71
Veteran
Veteran


Joined: 17 Aug 2005
Posts: 1869
Location: Switzerland (Romandie)

PostPosted: Thu Apr 18, 2013 11:08 am    Post subject: BASH: weird variable division [solved] Reply with quote

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 :evil:

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Apr 18, 2013 12:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Thu Apr 18, 2013 12:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dominique_71
Veteran
Veteran


Joined: 17 Aug 2005
Posts: 1869
Location: Switzerland (Romandie)

PostPosted: Thu Apr 18, 2013 12:46 pm    Post subject: Reply with quote

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 :roll:
_________________
"Confirm You are a robot." - the singularity
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum