views:

33

answers:

2

Hello, everyone.

I am trying to create a script, and one part requires showing lines with numeric values.

My basic syntax is:

echo $i | grep [0-9]

For example, I set i=12345, it should output 12345.

But on one server, it doesn't output anything (exactly the same commands).

I do not know how to Google this issue, I have tried "grep output different on other server", to no avail.

A: 

maybe it's a shell issue? some shells interpert [] differently try

echo "1234" | grep "[0-9]"

(with quotes)

also try

grep --version

to see if there is a different grep version

Nir Levy
+1  A: 

When using a regexp, either use egrep or grep -e to make sure the pattern is not treated as a plain string.

Aaron Digulla
I tried this, but the other server still outputs NOTHING.
Winterburn
Did you use quotes as Noir Levy suggested? There might be a file called "5" in that directory or something.
Aaron Digulla
I used " " and it worked. One last question, should I use "-e" everytime I use brackets on grep?
Winterburn