0

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
Programmer
  • 6,565
  • 25
  • 78
  • 125

2 Answers2

1

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
Pierre Arlaud
  • 4,040
  • 3
  • 28
  • 42
1

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 .`
bmk
  • 13,849
  • 5
  • 37
  • 46
  • I was going to edit my post for this. With both changes you should be good. – Pierre Arlaud Nov 28 '13 at 10:35
  • @ArlaudAgbePierre: Yes, I think that's true. – bmk Nov 28 '13 at 10:37
  • 1
    @Programmer: From the `csh` manpage: *Note also that '=' can be adjacent to both name and word or separated from both by whitespace, but cannot be adjacent to only one or the other.* – bmk Nov 28 '13 at 10:49