eg: not working.
Isacomment="I am a comment" | cut -b1; case ${Isacomment} in "I") echo
this is a comment; return 1;; *) echo this is not a comment ; return
0;; ; esac
Thanks for any help.
Let's reformat this a bit, so that the case statement stands out, OK?
Isacomment="I am a comment" | cut -b1;
case ${Isacomment} in
"I") echo this is a comment;
return 1;;
*) echo this is not a comment ;
return 0;;
;
esac
OK?
And, let's see what ksh(1) thinks a case statement should look like...
case word in [ [(]pattern [ | pattern ] ... ) list ;; ] ... esac
A case command executes the list associated with the first pat-
tern that matches word. The form of the patterns is the same as
that used for file-name generation (see File Name Generation
below). The ;; operator causes execution of case to terminate.
If ;& is used in place of ;; the next subsequent list, if any,
is executed.
OK, so it appears that, after the [case word in] clause, the ksh case
statement expects
a pattern, followed by
a list of statements, followed by
a pair of semicolons, optionally followed by
another pattern, statements, and a pair of semicolons.
Your case statement, OTOH, contains
a pattern [*)], followed by
a list of statements [echo this is not a comment ; return 0] followed by
a pair of semicolons [;;], followed by
a single semicolon.
My guess is that the single semicolon violates the ksh case statement
format, which appears to expect either 'esac' or another pattern at that
point.
> Thanks for any help.
HTH
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------
The demo isn't going to do anything, regardless of the case statement,
because this
Isacomment="I am a comment" | cut -b1;
does nothing. I suspect you want the pick off the first character of the
string in quotes, and put it into the variable.
Isacomment=$(echo "I am a comment" | cut -b1)
That is one way. There's a better way though, but lets
work with that first.
ksh -c 'Isacomment=$(echo I am a comment | cut -b1 ) ; \
case ${Isacomment} in I) echo TRUE ;; *) echo Not a comment ;; esac'
But what you really do want to do is put a lot of that
into quotes:
ksh -c 'Isacomment="$(echo "I am a comment" | cut -b1 )" ; \
case "${Isacomment}" in "I") echo "TRUE" ;; *) echo "FALSE" ;; esac'
I'm assuming that in actual use the variable will be set
elsewhere, and it would look more like this example,
which is simplified nice ways:
Isacomment="# some kind of a comment string" # <== on its own line
...
ksh -c 'case "${Isacomment}" in "#"*) echo "TRUE" ;; \
*) echo "FALSE" ;; esac'
If you actually do want to embed the variable
assignment, this will do the same:
ksh -c ' Isacomment="# some kind of a comment string" ; \
case "${Isacomment}" in "#"*) echo "TRUE" ;; *) echo "FALSE" ;; esac'
--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) fl...@apaflo.com