grep
doesn't have an option to interpret its command-line arguments as text to be searched. The normal way to grep
a string is to pipe the string into grep
's standard input:
$ echo 'There once was a man from Nantucket
Who kept all his cash in a bucket.
But his daughter, named Nan,
Ran away with a man
And as for the bucket, Nantucket.' | grep -i nan
There once was a man from Nantucket
But his daughter, named Nan,
And as for the bucket, Nantucket.
$
As you see here, you can echo
strings containing more than one line of text. You can even type them into the shell interactively, if you like.
If this doesn't meet your needs, maybe you could explain why piping isn't an acceptable solution?
Maybe pipe some kind of text data to
grep
? So maybe something likeprintf "various\ntext to grep here" | grep "text"
will produce "text to grep here" – Alex – 2014-05-02T03:12:39.933