Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Unix Operating Systems > Debian Linux > Debian Linux support

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 05:01 AM
Henk Oegema
 
Posts: n/a
Default While loop problem

The bash program below is a (test) program to test the values of a USB
interface card.

The lines in front are only for clarification.

When an input port on the USB card gets activated, then the variable
digital_inputs changes (in line 11).
I checked that with line 12
The next time the while statement executes (in line 8) it should be false,
and the while loop should stop.

This doesn't happen.

What is my mistake? (don't get a syntax error)



1#!/bin/bash
2
3 digital_inputs=0
4 portstatus_dec=0
5
6
7
8 while [ $digital_inputs=$portstatus_dec ];
9 do
10 sleep 1
11 digital_inputs=`k8055 -m:1 2>/dev/null | tail -1 | cut -d';' -f2`
12 echo $digital_inputs
13 done
14
15 echo "There is an alarm"

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 05:01 AM
El Tux
 
Posts: n/a
Default Re: While loop problem

On Wed, 27 Feb 2008 21:01:49 +0100, Henk Oegema wrote:

> The bash program below is a (test) program to test the values of a USB
> interface card.
>
> The lines in front are only for clarification.
>
> When an input port on the USB card gets activated, then the variable
> digital_inputs changes (in line 11).
> I checked that with line 12
> The next time the while statement executes (in line 8) it should be
> false, and the while loop should stop.
>
> This doesn't happen.
>
> What is my mistake? (don't get a syntax error)
>
>
>
> 1#!/bin/bash
> 2
> 3 digital_inputs=0
> 4 portstatus_dec=0
> 5
> 6
> 7
> 8 while [ $digital_inputs=$portstatus_dec ]; 9 do


In a test, you need a space on each side of the equals sign.

> 10 sleep 1
> 11 digital_inputs=`k8055 -m:1 2>/dev/null | tail -1 | cut -d';'
> -f2` 12 echo $digital_inputs
> 13 done
> 14
> 15 echo "There is an alarm"


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 05:01 AM
s. keeling
 
Posts: n/a
Default Re: While loop problem

El Tux <nope@spamsucks.invalid>:
> On Wed, 27 Feb 2008 21:01:49 +0100, Henk Oegema wrote:
> >
> > 1#!/bin/bash
> > 2
> > 3 digital_inputs=0
> > 4 portstatus_dec=0
> > 8 while [ $digital_inputs=$portstatus_dec ];

>
> In a test, you need a space on each side of the equals sign.


And, to quote Ben at linuxgazette.net, *always* double-quote your
variables. They may be empty.

> > 10 sleep 1
> > 11 digital_inputs=`k8055 -m:1 2>/dev/null | tail -1 | cut -d';' -f2`
> > 12 echo $digital_inputs
> > 13 done
> > 14
> > 15 echo "There is an alarm"



--
Any technology distinguishable from magic is insufficiently advanced.
(*) http://blinkynet.net/comp/uip5.html Linux Counter #80292
- - http://www.faqs.org/rfcs/rfc1855.html Please, don't Cc: me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 01:58 PM
Henk Oegema
 
Posts: n/a
Default Re: While loop problem

s. keeling wrote:

>
> And, to quote Ben at linuxgazette.net, *always* double-quote your
> variables. They may be empty.
>

Yep.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 01:56 AM
Unruh
 
Posts: n/a
Default Re: While loop problem

Henk Oegema <henk@oegema.com> writes:

>The bash program below is a (test) program to test the values of a USB
>interface card.


>The lines in front are only for clarification.


>When an input port on the USB card gets activated, then the variable
>digital_inputs changes (in line 11).
>I checked that with line 12
>The next time the while statement executes (in line 8) it should be false,
>and the while loop should stop.


>This doesn't happen.


>What is my mistake? (don't get a syntax error)


Put spaces on either side of the = in test.




>1#!/bin/bash
>2
>3 digital_inputs=0
>4 portstatus_dec=0
>5
>6
>7
>8 while [ $digital_inputs=$portstatus_dec ];
>9 do
>10 sleep 1
>11 digital_inputs=`k8055 -m:1 2>/dev/null | tail -1 | cut -d';' -f2`
>12 echo $digital_inputs
>13 done
>14
>15 echo "There is an alarm"


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:51 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62