You are not logged in.

#1 2008-02-03 03:04:40

dax965
Member
Registered: 2007-09-09
Posts: 35

too many arguments

I have a bash script and I'm getting this:

status.sh: line 36: [: too many arguments

Here's lines 35 through 37:

                        music=$(mocp -i | sed -ne 's/^Title: \(.*\)$/\1/p');
                        [ -z $music ] && music=$(mocp -i | sed -ne 's/File: .*\/\([^ .].*\)$/\1/p')
                        ptime=$(mocp -i | sed -ne 's/^TimeLeft: //p')

I didn't make this script, this is just for a status bar I'm whipping together.  Anyone know why I am getting this error?

Offline

#2 2008-02-03 03:10:10

peart
Member
From: Kanuckistan
Registered: 2003-07-28
Posts: 510

Re: too many arguments

Maybe your $music variable contains whitespace.  try wrapping it in quotes:

[ -z "$music" ] ...

Offline

#3 2008-02-03 04:04:54

dax965
Member
Registered: 2007-09-09
Posts: 35

Re: too many arguments

peart wrote:

Maybe your $music variable contains whitespace.  try wrapping it in quotes:

[ -z "$music" ] ...

Thanks. 


Also, I need help getting the volume number.  Here's the command I have right now

amixer get PCM | awk '/^  Front Left/ { print $5 }'

But that outputs

[100%]

How can I edit that to make it only say 100, not [100%]?

Offline

#4 2008-02-03 04:36:08

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: too many arguments

String editing is easier with sed:

amixer get Front | sed -ne '/^  Front Left/ s~.*\[\([0-9]*\)%\].*~\1~p'

It can be done with awk though, using the substring function:

amixer get Front | awk '/^  Front Left/ { print substr($5,2,length($5)-3) }'

Offline

#5 2008-02-03 05:18:37

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: too many arguments

dax965 wrote:

Also, I need help getting the volume number.  Here's the command I have right now

amixer get PCM | awk '/^  Front Left/ { print $5 }'

But that outputs

[100%]

How can I edit that to make it only say 100, not [100%]?

I like tr myself:

amixer get PCM | awk '/^  Front Left/ { print $5 }' | tr -d [%]

The -d switch makes tr delete characters instead of translating.

Regards.

Offline

Board footer

Powered by FluxBB