|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
Quote:
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 ? |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Korn shell script giving error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|