Solved

How to get this to evaluate right

Posted on 2006-06-11
2
178 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
Comment Utility
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
Comment Utility
Boy do I feel stupid -- I had 1 too many spaces afer the -f, thanks for the help!


0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now