0

I have posted a question earlier about this but now I understand the problem and thus want to repost. The * character is correctly interpreted in my csh script when not put in double quotes, but when I put it in double quotes, it is not correctly interpreted. Does anyone know how to make csh correctly interpret the * character. Below is my code:

#!/bin/csh
#set ans=`grep  -E hello\*i ~/wildcard/helloi.txt`
set ans=`grep  -E "hello\*i" ~/wildcard/helloi.txt`
echo $ans

The commented set ans works fine but the uncommented one does not. The input file contains the following :

helloiif
helli
helloi

All 3 should be printed.

Programmer
  • 6,565
  • 25
  • 78
  • 125

1 Answers1

0

Option 1 (with quotations marks, don't escape *)

grep -E "hello*i" ~/wildcard/helloi.txt

Option 2 (without quotation marks, must escape *)

grep -E hello\*i ~/wildcard/helloi.txt

Inside double quotes, csh always expands things it knows, such as *, $, etc.

supergra
  • 1,578
  • 13
  • 19