Search code examples
cshtcsh

Evaluating a command and assigning it to variable


How do I evaluate an example command and assign it to a variable without printing the results out using tcsh

 #!/bin/tcsh   
 set path=/home/uu/Desktop/ 
 egrep inn $path/filename.txt | grep en | awk '{print $3}'

Basically, I want to assign this line of code after executing it to a variable so that I can print it out later

egrep inn $path/filename.txt | grep en | awk '{print $3}'

Solution

  • In tcsh, you can assign the output of a command into a variable by enclosing the command into backticks such as:

    set result=`egrep inn $path/filename.txt | grep en | awk '{print $3}'`