Any ideas how to clear this error as it seems I dont understand if,do,while and els commands
#!/bin/ksh
set -x
print "This script creates test messages"
print "Please enter test case name"
read testcasename
echo $testcasename
skipfield=Y
while [ $skipfield != "Y" ]
print "Do you want to skip this field Y/N?"
read skipfield
do
done this done is causing syntax error
CHOICE=N
while [ $CHOICE != "Y" ];
do
print "Please enter in field 1 Version"
read version
if [[ "${#version}" -lt 4 ]] ; then
print -n $version >> $testcasename
else
print "too many bytes"
fi
print "Do you want to continue Y/N?"
read CHOICE
done
CHOICE2=N
while [ $CHOICE2 != "Y" ];
do
print "Pleasent in field 2 Date"
read date
if [[ "${#date}" -lt 9 ]] ; then
print -n $date >> $testcasename
else
print "too many bytes"
fi
print "Do you want to continue Y/N?"
read CHOICE2
done
exit
# this is forever loop -almost, try to press CTRL-D ... loop will end
skipfield=Y
while [ $skipfield != "Y" ]
print "Do you want to skip this field Y/N?"
read skipfield
do
: # between do and done, like then and fi need 1-n commands
# : = builtin nop command, return always true
done
Why ?
while command(s)
do
...
done
=> exit code of command, between while and do you can put command lines, but return code of last line is the important.
=> read some and press EOF = exit code is not 0 => while end
So, maybe this is better:
# this will end if you press Y or CTRL-D
while
print "Do you want to skip this field Y/N?"
read skipfield
[ "$skipfield" != "Y" ] # - without " " you get error if press ENTER or CTRL-D
do
:
done