Solved

How to get this to evaluate right

Posted on 2006-06-11
2
180 Views
Last Modified: 2012-05-05
COUNTER=1
                 while [  $COUNTER -lt 8 ]; do
                        doorstatus=`echo $sensedvalues | cut -d ','  -f $COUNTER`;
                         let COUNTER+=1
         done


How can I get $COUNTER to work.  I want to get the value of each column from the cut.  But $COUNTER doesn't break down to a number.  so the line errors.

Thanks

0
Comment
Question by:Tigger996
2 Comments
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 16883301
WFFM (Works Fine For Me). I tried your script except I inserted an echo command to monitor the value of doorstatus, and I gave sensedvalues a value (which I assume you do elsewhere):

15:41:27$ cat x.sh
#!/bin/sh
#set -x
sensedvalues='a,b,c,d,e,f,g,h'
COUNTER=1
while [  $COUNTER -lt 8 ]; do
  doorstatus=`echo $sensedvalues | cut -d ','  -f $COUNTER`;
  echo "doorstatus = $doorstatus"
  let COUNTER+=1
done
15:41:33$ ./x.sh
doorstatus = a
doorstatus = b
doorstatus = c
doorstatus = d
doorstatus = e
doorstatus = f
doorstatus = g
15:41:52$

If you uncomment "set -x" you can see COUNTER incrementing - no problem.

Do you have a "#!/bin/sh" line at the front of your script? Otherwise just possibly some other shell is trying to interpret it. Failing that, it's a bit of a mystery - try inserting "set -x" to see better what's happening.
0
 

Author Comment

by:Tigger996
ID: 16883365
Boy do I feel stupid -- I had 1 too many spaces afer the -f, thanks for the help!


0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question