Programmer
Programmer

Reputation: 6753

How to use grep in csh script

Below is a simple csh script I wrote. But the set does not work. Can anyone please help me with the error.

#!/bin/csh
echo "hello"
set ans ='grep -r hello ./'
echo ans

Tried back quotes still not working:

   #!/bin/csh
echo "hello"
set ans =`grep -r hello .`
echo $ans

Upvotes: 0

Views: 12499

Answers (2)

Pierre Arlaud
Pierre Arlaud

Reputation: 4131

You need to use backquotes `` and not simplequotes ''.

Also variables are instanciated without a dollar but you need to access them like $ans

#!/bin/csh
echo "hello"
set ans =`grep -r hello .`
echo $ans

Upvotes: 1

bmk
bmk

Reputation: 14147

To get the value of a variable you have to add a $ to the beginning:

echo $ans

Furthermore you should remove the space in front of the = sign:

set ans=`grep -r hello .`

Upvotes: 1

Related Questions