- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: a scripting question
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
Forums
Discussions
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
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
12-06-2001 01:17 PM
12-06-2001 01:17 PM
a scripting question
#!yourshell
pattern="ab|bb"
c="ab"
case $c in
$pattern) print $c;;
ab) print here;;
*) print "not found";;
esac
sh or ksh will return "here". how do I code this example to return "ab", which is what it does when using the /usr/dt/bin/dtksh shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2001 01:29 PM
12-06-2001 01:29 PM
Re: a scripting question
I can think of one work around it works for you.
#!/usr/bin/ksh
pattern="ab|bb"
c="ab"
cat << EOF > /tmp/sh$$
case $c in
$pattern ) print $c;;
ab) print here;;
*) print "not found";;
esac
EOF
ksh /tmp/sh$$
rm /tmp/sh$$
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2001 01:39 PM
12-06-2001 01:39 PM
Re: a scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2001 02:04 PM
12-06-2001 02:04 PM
Re: a scripting question
$regexp="ab|b";
...
if (/$regexp/) {
...
}
Within ksh you might be able to use the "eval" shell command (if it is a small list of case statements). eg-
x="ab|b"
val="b"
eval "case $val in $x) echo yes;; *) echo no;; esac"
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2001 02:11 PM
12-06-2001 02:11 PM
Re: a scripting question
This workaround should work (without intermediate files)
#!/bin/sh
pattern="ab|bb"
c="ab"
eval "case $c in
$pattern) print $c;;
ab) print here;;
*) echo \"not found\";;
esac"
Regards,
Paga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2001 02:21 PM
12-06-2001 02:21 PM
Re: a scripting question
i believe using the eval within the if-then-else construct to more useable for my programming.
if eval [[ $c = @($pattern) ]] ;then
print $c
elif eval [[ $c = "ab" ]] ;then
print here
else
print "not found"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2001 02:37 PM
12-06-2001 02:37 PM
Re: a scripting question
However, it would have been nice if you had given your program completely so that we might have suggested to use if-then-else construct instead of wasting our time to think about a workaround.
We only can think about the solutions based on the information you gave.
-Sri