Solved

How to get this to evaluate right

Posted on 2006-06-11
2
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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