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
Solved

KSH Case statement pattern with space in

Posted on 2004-04-18
6
3,052 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
substring method in java 1 129
isEverywhere  challenge 19 82
Fibonacci challenge 11 133
Problem to App 4 97
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

860 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