You need to use a herestring (`<<<`) here to pass the string as input to `grep`, herestring returns a file descriptor, `grep` can then operate on that:
$ grep -ni "^li" <<<"linux
loan
litmus
launch"
**Output:**
1:linux
3:litmus
If your shell doesn't support herestrings, many shells don't, you can print your string and pipe it to `grep`:
$ echo "linux
loan
litmus
launch" | grep -n -i "^li"
1:linux
3:litmus
Or use heredoc (`<<`):
$ grep -ni "^li" <
> loan
> litmus
> launch
> EOF
1:linux
3:litmus