Solved

How to get this to evaluate right

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CENTOS7 DL380 G5  failed to install even after hpsa allowed 5 1,014
Linux script help 27 242
improve Shell script 5 143
Set-Top-Box hardware and Open Source! 8 144
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 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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 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

22 Experts available now in Live!

Get 1:1 Help Now