12-10-2008
Help needed in Switch Case
Hi Experts team,
i wish to use switch case in unix.
my req is
case $code in
1111)
echo "1111"
1112)
echo "1112"
*)
echo "default"
esac
see eventhough for particular case 1111 , it is always execute the default statement *), if i code like this.
How can handle numeric values in switch case in shell scripts.
Please explain
Thanks a lot 8)
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
In a Case switch, how to ignore case sensitive in the test:
e.g.
case "$field" in
"TEST) action1;;
*) action2;;
esac
How to go in action1 in case of $field = TEST , or Test , or test or .... without enumerating all possibilities...
Thanks,... (1 Reply)
Discussion started by: annelisa
1 Replies
2. Shell Programming and Scripting
HELLO ALL,
URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE.
FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY
and the CITY column records will be: Newyork
washington
... (1 Reply)
Discussion started by: abhilash mn
1 Replies
3. Shell Programming and Scripting
Hi,
In below code, i am expecting the output has
Bye
Bye
But i am getting has
Bye
Hi
Code:
#!/usr/bin/bash
var="Hi"
cat txt.txt | while read var1
do
next="Bye"
case $var in
Hi) (1 Reply)
Discussion started by: Balamani
1 Replies
4. Shell Programming and Scripting
can anyone post a sample code for a switch case in shell (1 Reply)
Discussion started by: sumit the cool
1 Replies
5. Shell Programming and Scripting
I started writing a script to save the files from a camera I got the other day, which mounts in /Volumes , and I got into it and started building this menu. The only problem is that the switch case is coming up as a syntax error at the parenthesis after a case. Here is the code:
while :
do
... (2 Replies)
Discussion started by: snakemasterAK
2 Replies
6. Shell Programming and Scripting
My switch case is not working properly. When I press 6 or 'r' it prints out all the names of the project and the error message.
#!/bin/bash
while true; do
read -p "Enter project number (1/2/3/10/20/30):" menu
#grabs the informations of the project number and stores it into a menu... (1 Reply)
Discussion started by: Rapcher
1 Replies
7. Shell Programming and Scripting
case "$inputs" in
sapte)
find /pools/home_unix/sapte/work/models/model -name "*.xml" exec rm -i {} \;;
ckm1)
find /pools/home_unix/ckm1/work/models/model -name "*.xml" exec rm -i {}
\;;
I am getting error like as below.
./menu1.sh: line 144: syntax error near unexpected token `)'... (4 Replies)
Discussion started by: lathigara
4 Replies
8. Programming
Hi
Am pretty new to C..
Am trying to pass the arguments from command line and use them in switch case statement..
i have tried the following
#include <stdlib.h>
main(int argc, char* argv)
{
int num=0;
if ( argc == 2 )
num = argv;
printf("%d is the num value",num);
switch ( num )
... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies
9. Shell Programming and Scripting
Hi All,
I have a requirement to write shell script in which we have to test three cases considering ip connection which differentiate the tool's name as per as the ip address in the file.txt .
<ip1>,<ip2>,<ip3> address belongs to Tool1
<ip4>,<ip5>,<ip6> address belongs to Tool2
if... (12 Replies)
Discussion started by: netdbaind
12 Replies
10. Shell Programming and Scripting
Hi there,
I'm trying to run a simple script,but i'm always getting this error
Syntax error: word unexpected (expecting "in")I have searched many sites,like this,but i dont get it,it looks good so far,but wont work,maybe someone can help me.
Here is the Script
#!/bin/bash
while :
do... (6 Replies)
Discussion started by: JustAnUser
6 Replies
LEARN ABOUT OPENSOLARIS
escape
escape(1) Mail Avenger 0.8.3 escape(1)
NAME
escape - escape shell special characters in a string
SYNOPSIS
escape string
DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result.
EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string:
$ var='; echo gotcha!'
$ eval echo hi $var
hi
gotcha!
$
Using escape, one can avoid executing the contents of $var:
$ eval echo hi `escape "$var"`
hi ; echo gotcha!
$
A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For
example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient:
#!/bin/sh
formail -x to -x cc -x resent-to -x resent-cc
| fgrep "$1" > /dev/null
&& exit 0
echo "<$1>.. address does not accept blind carbon copies"
exit 100
To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt
script:
bodytest reject_bcc `escape "$RECIPIENT"`
SEE ALSO
avenger(1),
The Mail Avenger home page: <http://www.mailavenger.org/>.
BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells.
AUTHOR
David Mazieres
Mail Avenger 0.8.3 2012-04-05 escape(1)