Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
echo "Here's \$7.80" |
grep -oE [$][0-9]+.[0-9]+gives me my desired $7.80
But:
1. I had to escape the $7, so why:
a. CAN'T I escape the . in $7.80
b. IS IT OPTIONAL to escape the . in my
regular expression?echo "this.that" | grep -o \. will not match the .
Why do I need to escape the backslash? I thought whenever you had a character you wanted to match literally you just needed to precede it with a backslash. The proper regex, which is \\. looks like I'm looking for a backslash followed by any single characterecho "this.that" | grep -o '.' interprets the special meaning of '.' If that's the case, why won't
echo "this.that" | grep -o '\\.' match exactly a dot?Besides interpolating variables, is there a difference between using single quotes and double quotes? In Unix? In Kornshell?
Thanks.

Using the ' ' single quotes turned off shell expansion, which means that it was looking for the literal string of 2 backslashes followed by a dot.
========================================================
[root@perlman ~]# echo "this.that" | grep -o "\."
.

echo "this.that" | grep -o "\." To match the . why do I need to backslash escape the \?
And can you explain the dollar sign example I had? Thanks.

Based on this and your other related questions, you should pick up a couple reference books.
Learning the Korn Shell, 2nd Edition
http://www.oreilly.com/catalog/korn...Mastering Regular Expressions, Third Edition
http://www.oreilly.com/catalog/9780...

I'm actually using Learning the Kornshell lol it's not very good. It said to use the * like:
*(exp) for 0 or more exp. I tried that and it didn't work, but (exp)* does. As for Mastering Regular Expressions, doesn't that cover regular expressions in perl?

As for Mastering Regular Expressions, doesn't that cover regular expressions in perl?
It covers details and differences between numerous languages...Perl, php, shell, java, etc.

I'm actually using Learning the Kornshell lol it's not very good.
How about reading the man page, which is the main resource used in most shell scripting books.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |