syntax error: operand expected (error token is " ")

syntax error: operand expected (error token is " ")

Post by Perry Whela » Sat, 17 Jul 2004 02:45:46



How can I resolve this error:
./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
(error token is " ")
./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
(error token is " ")
./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
(error token is " ")
./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
(error token is " ")
./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
(error token is " ")
./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
(error token is " ")
./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
(error token is " ")
./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
(error token is " ")
./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
(error token is " ")
10176147

(notice it does infact have the desired value too)
...from this code:

#!/bin/bash
COMMANDS="awk"
for i in $COMMANDS
do
        X=`echo $i|tr [a-z] [A-Z]`
        export $X=`which $i`
done
FILE="/proc/stat"
while read ARRAY_0
do
        ROW_0=`echo "$ARRAY_0" | $AWK '/cpu0 / {print $2}'`
        (( ROW_0 = $ROW_0 ))
done < $FILE
echo ${ROW_0}
exit 0

 
 
 

syntax error: operand expected (error token is " ")

Post by j.. » Sat, 17 Jul 2004 03:54:09



> How can I resolve this error:
> ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> (error token is " ")
> ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> (error token is " ")
> ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> (error token is " ")
> ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> (error token is " ")
> ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> (error token is " ")
> ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> (error token is " ")
> ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> (error token is " ")
> ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> (error token is " ")
> ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> (error token is " ")
> 10176147

> (notice it does infact have the desired value too)
> ...from this code:

> #!/bin/bash
> COMMANDS="awk"
> for i in $COMMANDS
> do
>         X=`echo $i|tr [a-z] [A-Z]`

This should be

X=`echo $i|tr '[a-z]' '[A-Z]'`

Quote:>         export $X=`which $i`

This should be

export X=`which $i`

But I'm not sure why you're doing it.

1. Why are you uppercasing the name of awk? You don't use it anywhere,
   and you reassign X in the next line anyway.

2. You pass which the name as it's set in i, not the uppercased name.

Quote:> done
> FILE="/proc/stat"
> while read ARRAY_0
> do
>         ROW_0=`echo "$ARRAY_0" | $AWK '/cpu0 / {print $2}'`
>         (( ROW_0 = $ROW_0 ))

What's this line intended to do? Why set a variable to the value it
currently has?

This is the reason for the error messages. If you really are trying to
do that, the syntax should be

ROW_0=$ROW_0

But there's no reason to do that I can see.

Quote:> done < $FILE
> echo ${ROW_0}
> exit 0

No output will be produced unless "cpu0 " is in the last line of the
file.

If what you're trying to do is get the second field from the cpu0 line
of /proc/stat, try this

#!/bin/bash
FILE="/proc/stat"
ROW_0=`awk '
  /cpu0 / {print $2}
' $FILE`
echo ${ROW_0}

Joe
--
We can't all be heroes because someone has to sit on the curb and
clap as they go by.
  - Will Rogers

 
 
 

syntax error: operand expected (error token is " ")

Post by Perry Whela » Sat, 17 Jul 2004 05:01:23




> > How can I resolve this error:
> > ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> > (error token is " ")
> > ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> > (error token is " ")
> > ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> > (error token is " ")
> > ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> > (error token is " ")
> > ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> > (error token is " ")
> > ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> > (error token is " ")
> > ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> > (error token is " ")
> > ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> > (error token is " ")
> > ./cpu_percentage: line 16: ((: ROW_0 =  : syntax error: operand expected
> > (error token is " ")
> > 10176147

> > (notice it does infact have the desired value too)
> > ...from this code:

> > #!/bin/bash
> > COMMANDS="awk"
> > for i in $COMMANDS
> > do
> >         X=`echo $i|tr [a-z] [A-Z]`

> This should be

> X=`echo $i|tr '[a-z]' '[A-Z]'`

> >         export $X=`which $i`

> This should be

> export X=`which $i`

> But I'm not sure why you're doing it.

> 1. Why are you uppercasing the name of awk? You don't use it anywhere,
>    and you reassign X in the next line anyway.

> 2. You pass which the name as it's set in i, not the uppercased name.

> > done
> > FILE="/proc/stat"
> > while read ARRAY_0
> > do
> >         ROW_0=`echo "$ARRAY_0" | $AWK '/cpu0 / {print $2}'`
> >         (( ROW_0 = $ROW_0 ))

> What's this line intended to do? Why set a variable to the value it
> currently has?

> This is the reason for the error messages. If you really are trying to
> do that, the syntax should be

> ROW_0=$ROW_0

> But there's no reason to do that I can see.

> > done < $FILE
> > echo ${ROW_0}
> > exit 0

> No output will be produced unless "cpu0 " is in the last line of the
> file.

> If what you're trying to do is get the second field from the cpu0 line
> of /proc/stat, try this

> #!/bin/bash
> FILE="/proc/stat"
> ROW_0=`awk '
>   /cpu0 / {print $2}
> ' $FILE`
> echo ${ROW_0}

> Joe
> --
> We can't all be heroes because someone has to sit on the curb and
> clap as they go by.
>   - Will Rogers

Thanks Joe, but the reason for the while read i do is to take an accurate
snapshot of the /proc/stat file, rather than reading each time I get a
value.

I got it figured out, and now also realize (after rereading my bash book,
again) that my logic was borken before...

Here's what I did:
while read ARRAY_0
   do
           ROWS_0[$[++N]]=$ARRAY_0
   done < $FILE

   N=0
   while [ $[++N] -le ${#ROWS_0[*]} ]
   do
           ALL_USER0=`echo "${ROWS_0[1]}" | $AWK '{print $2}'`
done

echo $ALL_USER0 ;#now works perfectly...

 
 
 

1. startx returns errors "Not a declared device" or "Chipset string expected"

I am tring to edit XF86Config to get the startx command
working.  I have installed the X server which comes with the
Slackware 3.5 CD.  My video card is an ATI Mach32
Graphics Ultra Pro ISA 2048K.

The error messages that the startx command returns provide
line references at the end of the XF86Config file.  
startx seems to boggle at the entry for "Identifier" in the
"Graphics device section" and variously reports the error
messages referenced in the Subject line above.  I have tried
ATI-Mach32, ATI 68800-6 (which is reported by SuperProbe),
svga and Generic svga for the "Identifier" entry but to no
avail.

What is actually meant by a declared device?

Does anyone have any suggestions?

Thanks in advance for your help.

Michael Eisenstadt

2. Debian, Alsa & SB Live!

3. Type "(", ")" and "{", "}" in X...

4. Change Monitor Refresh

5. GETSERVBYNAME()????????????????????"""""""""""""

6. Setup of Dumb Terminal off Linux

7. APACHE Error: "Signaling Error: error already pending"

8. Error in 5.0.5 install

9. tinyX gives "xinit: Unknown error (errno 0): Client error." error and dies

10. gcc error: "elf error: file insn-attrtab.o: elf_strptr: Request error: no string table"

11. Install error on G3: "error unpacking archive: unknown error"

12. HELP: 3-Serial Ports ("Input/output error")

13. Error: setlocale(LC_TYPE, "")