- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Pattern matching for variables within a korn shell...
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
Discussions
Discussions
Discussions
Forums
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
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
тАО02-12-2002 03:42 AM
тАО02-12-2002 03:42 AM
pattern match testing in a korn shell script to test a variable.
Put another way,
Is pattern matching only available for use on lines in a file (with utils like sed, grep awk etc) or can I use it on a variable in a script file?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2002 03:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2002 04:02 AM
тАО02-12-2002 04:02 AM
Re: Pattern matching for variables within a korn shell program
Extended pattern matching is available in the shell for if and case statements etc.
Excerpt from 'man sh-posix':-
In addition to the notation described in regexp(5), sh recognizes composite patterns made up of one or more pattern lists separated from
each other with a |. Composite patterns can be formed with one or more of the following:
?(pattern-list) Matches any one of the given patterns.
*(pattern-list) Matches zero or more occurrences of the given
patterns.
+(pattern-list) Matches one or more occurrences of the given
patterns.
@(pattern-list) Matches exactly one of the given patterns.
!(pattern-list) Matches anything, except one of the given
patterns.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2002 04:09 AM
тАО02-12-2002 04:09 AM
Re: Pattern matching for variables within a korn shell program
For instance:
VAR=hello
echo $VAR|grep "el"
could be done internally with:
if [[ ${VAR} = *el* ]];
then...
or using an example of the shell extensions:
if [[ ${VAR} = *(?)el*(?) ]];
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2002 04:18 AM
тАО02-12-2002 04:18 AM
Re: Pattern matching for variables within a korn shell program
you have also a second way to set a value to a variable: ( this is called command substitution )
var=`pwd` # these are back- ticks, this syntax will be understood by all shells, even the Bourne- shell accepts it
var=$(pwd) # this syntax can be used for ksh and POSIX shell
# pwd
/home/peter
# var=`pwd`
# echo $var | grep 'peter'
/home/peter
#
Allways stay on the bright side of life!
Peter