r47463
asked on
KSH Case statement pattern with space in
How can I get a pattern to have a space in, for use in a case statement? I have two words which I would like to use.
For example, this obviously doesn't work, but shows what I'm trying to do:
word1 word2)
...
;;
I would also like to use wild cards for this so that "wo wo" would work.
If this isn't possible, how can I use wildcards on a string in an if statement please?
Thanks
For example, this obviously doesn't work, but shows what I'm trying to do:
word1 word2)
...
;;
I would also like to use wild cards for this so that "wo wo" would work.
If this isn't possible, how can I use wildcards on a string in an if statement please?
Thanks
#!/bin/sh
a="word1 word2"
case "$a" in
"word1 word2") echo matched ;;
*) echo does not match ;;
esac
a="word1 word2"
case "$a" in
"word1 word2") echo matched ;;
*) echo does not match ;;
esac
FYI
in ksh88i I was unable to get the following to work for a="word word"
"wo* wo*") ...
wo*\ wo*) ...
but both of these did:
"word word") ...
wo*) ...
in ksh88i I was unable to get the following to work for a="word word"
"wo* wo*") ...
wo*\ wo*) ...
but both of these did:
"word word") ...
wo*) ...
ASKER
Thanks all. Unfortunately so far I haven't been able to get any of these to work.
dtkerns - I'll try what you mentioned tonight.
At the moment the only way I can get it to work with two words is to use arguments, which doesn't seem like the right way to go about it, and doesn't allow me to use a wildcard on the string in an IF statement.
dtkerns - I'll try what you mentioned tonight.
At the moment the only way I can get it to work with two words is to use arguments, which doesn't seem like the right way to go about it, and doesn't allow me to use a wildcard on the string in an IF statement.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PS notice you have to use 'real' REs not (k)sh file expansion REs
wo*\ wo*) ;;