UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 11th, 2006, 10:36 AM
asty asty is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 94 asty User rank is Private First Class (20 - 50 Reputation Level)asty User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 16 h 8 m
Reputation Power: 5
Korn shell script giving error

I am sorry, this is really trivial, yet I am not able to understand what the problem is!
I am using korn shell and running this script

Code:
#!/bin/ksh
keep=3
while [ $keep -eq 1 ]; do
echo $keep
keep=$(($keep-1))
done

I am getting this error: `keep=$' unexpected

I am not able to understand it because
keep=$(($keep-1)) works fine on prompt.

Please help regarding this.
Thanks
Asty

Reply With Quote
  #2  
Old August 11th, 2006, 10:58 AM
mu's Avatar
mu mu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Dublin, Ireland
Posts: 174 mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 39 m 56 sec
Reputation Power: 39
Quote:
Originally Posted by asty
I am sorry, this is really trivial, yet I am not able to understand what the problem is!
I am using korn shell and running this script

Code:
#!/bin/ksh
keep=3
while [ $keep -eq 1 ]; do
echo $keep
keep=$(($keep-1))
done

I am getting this error: `keep=$' unexpected

I am not able to understand it because
keep=$(($keep-1)) works fine on prompt.

Please help regarding this.
Thanks
Asty


The problem is that it's not entering the loop, as a result of the condition you're specified (while $keep -eq 1), keep is initially 3 so it will not enter the loop. Perhaps you meant while $keep -ne 0 ?

Reply With Quote
  #3  
Old August 11th, 2006, 11:13 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 17 m 10 sec
Reputation Power: 48
try:
Code:
#!/bin/ksh
keep=3
while  [[ $keep -gt 0 ]]; do
        echo $keep
        keep=$(($keep-1))
done


Use [[ ]] for tests in ksh. It allows more flexibility.
There are other test numeric operators:
-gt greater than
-lt less than
-eq equal
-ne not equal

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Korn shell script giving error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT