Solved

How to get this to evaluate right

Posted on 2006-06-11
2
182 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 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