Search code examples
unixgreptcsh

Grep a path containing an environment variable and using it


I'm using tcsh, and I'm trying to grep a path from a file with several ID, I'm doing:

grep I241149 $ENV_CASTRO/ALL_CMD_LINES.BAK | grep -o \$"ENV_CASTRO.*.asm"

that gets me:

$ENV_CASTRO/central/WS678/test_do_all.asm

but if I try

cp `grep I241149 $ENV_CASTRO/ALL_CMD_LINES.BAK | grep -o \$"ENV_CASTRO.*.asm"` .

it prompts

cp: cannot stat `$ENV_CASTRO/central/WS678/test_do_all.asm': No such file or directory

How do I tell tcsh that the output of grep contains a $ that means it is an environment variable and is not plain text?

Thanks in advance.


Solution

  • eval is your friend ....

    eval cp `grep I241149 $ENV_CASTRO/ALL_CMD_LINES.BAK | grep -o \$"ENV_CASTRO.*.asm"` .
    

    I don't have the time to create files to test this.

    I hope this helps.