![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| anyone ever play with omniback(data protector) command "omnir"? | mr_manny | HP-UX | 1 | 02-01-2008 11:10 PM |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 03:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 01:52 AM |
| Please Help (Urgent) - Comparing 2 files with "awk" | zom_chp | Shell Programming and Scripting | 10 | 03-30-2005 07:34 AM |
| Error : "No data written to object that was write locked" | nileshkarania | UNIX for Dummies Questions & Answers | 1 | 06-07-2003 11:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
comparing scalars contaning "DOUBLE QUOTES" as data
Hello to all,
Does anyone know the solution ? Two strings A and B are present. I want to check whether B is a Substring of A. 1. The value of A is - 29 * * * /bin/ls "test" "tmp*" "log*" (Note: Pl note that A contains DOUBLEQUOTES, ASTERISK & FRONTSLASH) 2. The value of B is - /ls "test" "tmp*" "log*" (Note: again B contains DOUBLEQUOTES, ASTERISK & FRONTSLASH) Since the variable scalars A and B have DOUBLEQUOTES as a part of the data stored "=~" operator is not working. [ $A =~ $B ] - results in error.. Is there any other way (any sed/awk/perl one liners). Requesting help to solve this. Thanks rssrik |
|
||||
|
First of all, you need to learn to quote arguments properly. Simply double-quote anything with a variable in it, and you should be fine, most of the time.
If the strings also contain regex specials (in this case, asterisks), those need to be escaped somehow, or you need to use a different comparison function. May I suggest the plain old case statement? Code:
case $A in *"$B"*) echo "$A contains $B";; *) echo does not;; esac Last edited by era; 04-20-2008 at 08:12 AM.. Reason: Had $A and $B mixed up |
|
||||
|
The double quotes are not the problem, it's that you are using the regular expression match operator on something which is just a string, and which happens to contain characters which have a special meaning in regular expressions. " *" (space asterisk) matches zero or more spaces in a regular expression, but doesn't match a literal asterisk. "log*" matches "lo", "log", "logg", "loggg", "logggg" etc but doesn't match "log*".
|
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|