- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell scripting - test for similarity
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
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
тАО05-21-2006 09:33 PM
тАО05-21-2006 09:33 PM
how does one test for similarity in shell scripting? "If" doesn't seem to accept wildcards.
I want something like, if the string is similar to Lo1, Lo2, Lo, then do something
I tried
if
[ $string = Lo* ]
then
exit
Its simple in perl, but here I have a shell script to modify.
-Alvi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 09:41 PM
тАО05-21-2006 09:41 PM
Re: shell scripting - test for similarity
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 09:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 09:49 PM
тАО05-21-2006 09:49 PM
Re: shell scripting - test for similarity
if [ $String = Lo1 ] && [ $string = Lo2 ]
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 09:59 PM
тАО05-21-2006 09:59 PM
Re: shell scripting - test for similarity
for wildcard, use the "case" instead of "if-then".
GOOD LUCK!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 10:17 PM
тАО05-21-2006 10:17 PM
Re: shell scripting - test for similarity
I dont' remember how its exactly written.
Check out the man pages.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2006 11:41 PM
тАО05-21-2006 11:41 PM
Re: shell scripting - test for similarity
you can grep for a pattern at the beginning of a string, e.g.:
#!/usr/bin/sh
PAR="$1"
PATTERN="Lo"
echo "$1" | grep -q ^"$PATTERN"
if [ $? = "0" ]
then
echo hit
else
echo no hit
fi
try the above with your string to compare as $1
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 02:26 AM
тАО05-22-2006 02:26 AM
Re: shell scripting - test for similarity
if [[ $string = Lo* ]]
then
exit
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2006 07:14 PM
тАО05-22-2006 07:14 PM
Re: shell scripting - test for similarity
The case and grep ideas worked perfectly. The if substring thing, though, I didn't get.
And Rodney, the double square brackets, exactly what I was looking for.
Thanks and Regards,
-Alvi