- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ksh script, compare two variables
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
08-19-2002 03:50 PM
08-19-2002 03:50 PM
ksh script, compare two variables
Suppose I have a variable, $str, that contains a bunch of text. I have another variable, $substr, that contains some other text.
I need to contruct a test to see if $str "contains" $substr. The trick is, I need to do this with builtins only, no awk, grep, etc.
I recall something with parameter expansion, like testing if ${str%$substr} = $substr....
Help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 04:09 PM
08-19-2002 04:09 PM
Re: ksh script, compare two variables
Take a look at the man pages for 'sh-posix'. You will see shell built-in pattern matching like:
${parameter##pattern}
${parameter%%pattern}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 04:16 PM
08-19-2002 04:16 PM
Re: ksh script, compare two variables
...and I should add that the Posix shell ('/usr/bin/sh' or '/sbin/sh') is really a superset of the Korn shell ('/usr/bin/ksh').
Hence you could look at either the man pages for 'sh-posix' or those for 'ksh' for more explanation of the shell pattern matching.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 04:23 PM
08-19-2002 04:23 PM
Re: ksh script, compare two variables
[[ "${str%${substr}*}" != "$str" ]] && echo $substr is within $str
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2002 05:18 PM
08-19-2002 05:18 PM
Re: ksh script, compare two variables
good catch! too bad you can't give yourself a ten pointer :-)
One big question, why don't you want to use "normal" pattern matching features like grep, awk, sed, perl ??
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2002 08:23 AM
08-20-2002 08:23 AM
Re: ksh script, compare two variables
Yeah, I knew I was close, I just had to think about it a while. The problem with using sed/awk/grep/etc is the performance hit.
I'm doing Timefinder scripting on an EMC Symmetrix, and I'm trying to get the run time of the script down as low as possible. We're doing Timefinder splits on a live Informix database (7.3), and the way Informix supports this is to temporarily block writes to disk. Needless to say, I want to make sure Informix blocks the writes for as short a period as possible.
I've done this in the past (non-grep/etc string compares in ksh), and using the ksh builtins is a HUGE performance boost. If you're looping through arrays, and have a lot of searches/compares to do, the grep's can add up...
Scott Riley
Stack Computer, Inc.