- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: using variables in case command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 07:43 AM
04-02-2002 07:43 AM
using variables in case command
case $var1 in
$var2 )
do stuff ;;
* )
do nothing ;;
esac
...where $var2 = "001|002|003" but $var2 is not being translated correctly, or at least how I thought it would be.
If I set $var2 to be a single value (without the pipes) it works fine.
Can anyone advise on the correct syntax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 07:53 AM
04-02-2002 07:53 AM
Re: using variables in case command
$var2 = '001|002|003'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 07:53 AM
04-02-2002 07:53 AM
Re: using variables in case command
OLD_FS=$FS
FS="|"
CASE
...
ESAC
FS=$OLD_FS
HTH
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 07:54 AM
04-02-2002 07:54 AM
Re: using variables in case command
case $var1 in
"$var2" )
do stuff ;;
* )
do nothing ;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 08:12 AM
04-02-2002 08:12 AM
Re: using variables in case command
case $var1 in
00[1-3] )
do stuff ;;
* )
do nothing ;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 11:48 AM
04-02-2002 11:48 AM
Re: using variables in case command
Gary,
Try escaping the pipe with backslash like this:
...where $var2 = "001\|002\|003"
and then: double quotes var2
case $var1 in
"${var2}" )
do stuff ;;
* )
do nothing ;;
esac
-Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 02:02 PM
04-02-2002 02:02 PM
Re: using variables in case command
you should always quote substitution, hence:
case "$var" in
"$var2) ... ;;
esac
Just my $0.02,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2002 02:01 AM
04-03-2002 02:01 AM
Re: using variables in case command
You have to put the exact "Constant" into the value of case. You are NOT allowed to do it as you mentioned :
case $var1 in
$var2 )
do stuff ;;
* )
do nothing ;;
esac
Syntax would be :
case $var1 in
'001|002|003')
do stuff ;;
* )
do nothing ;;
esac
No varaibles are allowed to be used in the constant expressions.
Magdi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2002 02:24 AM
04-03-2002 02:24 AM
Re: using variables in case command
thanks for all the input. I tried all of the above but unfortunately none of them worked. I'll try various combinations of your suggestions and let you know what happens.
Gary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 12:46 PM
04-04-2002 12:46 PM
Re: using variables in case command
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 05:59 PM
04-04-2002 05:59 PM
Re: using variables in case command
The syntax you need will be something like:
var1=$1
var2='00[1-3]'
case $var1 in
$var2) commands ;;
*) other commands ;;
esac
The issue is how you are assigning your variables. If you know what the allowable range of values for var2 is ahead of time, you can use the above style of assignment to test.
Mayhap if you could post how you're deriving var1 and var2 it would be helpful (if the above isn't what you're after).
Mark