Solved

KSH Case statement pattern with space in

Posted on 2004-04-18
6
3,042 Views
Last Modified: 2013-12-26
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

0
Comment
Question by:r47463
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 10855369
word1\ word2)  ;;
wo*\ wo*)        ;;
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10855668
#!/bin/sh
a="word1 word2"

case "$a" in
"word1 word2")  echo matched ;;
*)                        echo does not match ;;
esac
0
 
LVL 3

Expert Comment

by:dtkerns
ID: 10861043
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*) ...

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:r47463
ID: 10867763
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.
0
 
LVL 3

Accepted Solution

by:
dtkerns earned 55 total points
ID: 10869140
if you're only using the case for it's RE capabilities (as opposed to many if-else-if-else) you could use:

if expr "$a" : 'wo.* wo.*' > /dev/null
then
       echo true
else              
       echo false
fi                
0
 
LVL 3

Expert Comment

by:dtkerns
ID: 10869174
PS notice you have to use 'real' REs not (k)sh file expansion REs
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
Get filename and folder into excel 7 68
difference between String.subString() and String.subSequence() 6 169
Change to event 1 100
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now