?
Solved

select multiple options in shell script

Posted on 2009-12-26
6
Medium Priority
?
467 Views
Last Modified: 2013-12-26
Hi,

echo "1.Merge http trunk"
echo "2.Merge https trunk"
echo "3.Merge Java trunk"

I'm trying to use case statement for the above three options. Some times I need either 2 or all the three to take place at once. How can I do that using case statement or is there any better way to do that?
0
Comment
Question by:CharanR
6 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 26125475
How do you want the user to select multiple options?

1,2,3
1 2 3

or some other method?
0
 
LVL 1

Author Comment

by:CharanR
ID: 26125504
1,2,3 or 2,3 or 1,3  etc...
0
 
LVL 7

Expert Comment

by:vikas_madhusudana
ID: 26126276
can you try something like this.


echo "1.Merge http trunk"
echo "2.Merge https trunk"
echo "3.Merge Java trunk"
echo "4. both 1 and 2"
echo "5. both 1 and 3"
echo  "6 both  3 and 2"
echo  "6. all"





case $patter in

1) echo "1"

2) echo "2"

3)

4)

5)

6)
;;
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 1

Author Comment

by:CharanR
ID: 26127993
any other way ?
0
 
LVL 85

Accepted Solution

by:
ozo earned 1000 total points
ID: 26129200
#!/bin/bash
case $* in *1*) echo "1.Merge http trunk" ;; esac
case $* in *2*) echo "2.Merge https trunk" ;; esac
case $* in *3*) echo "3.Merge Java trunk"echo ;; esac
0
 
LVL 26

Assisted Solution

by:arober11
arober11 earned 1000 total points
ID: 26130954
Hi

Cleanest solution would be to use bash's "getopts" command, see one of the many tutorials for details e.g.

http://www.linux.com/archive/feature/118031
http://www.bash-hackers.org/wiki/doku.php/howto/getopts_tutorial
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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