Solved

KSH Case statement pattern with space in

Posted on 2004-04-18
6
3,064 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

628 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