cat command inside foreach loop not working
I have a file named abc.lst
Contents of abc.lst is as below (it has only one line) ------------------------------------- $xyz/list/source/abcxyz.f -------------------------------------- contents of file abcxyz.f is as below -------------------------------------- /asdc/sfd/wefef/wef/we/e/ewww/abc.v /afwef/trgt/wedwd/fvbtgb/axd.v /asdc/sfd/wefef/wef/we/e/ewww/abcd.v /afwef/trgt/wedwd/fvbtgb/axddd.v --------------------------------------- My shell script is as below --------------------------------------- foreach line ('cat abc.lst') cat $line >> temp1 end --------------------------------------- when i run this script i get a message saying cat: cannot open $xyz/list/source/abcxyz.f Instead of $line if i do cat $xyz/list/source/abcxyz.f >> temp1 then it works. I have defined $xyz variable as well in my terminal. Can you please let me know what is the problem in using $line variable? Thanks Praveen |
Hi,
this appears to be (t)csh, at which I'm a little rusty, but the problem seems to be that the variable $xyz is not defined in your script. Additionally, I'm not sure if this sort of "nesting" of variables would work anyway (but nothing ever surprises me about csh). Evo2. |
Thanks Evo,
I did set $xyz variable in my script but still i'm facing the same issue. Any other suggestions would be helpful Thanks Praveen |
Hi,
Quote:
My first advice would be to abandon (t)csh for scripting (and for interactive use if possible). My second piece of advice would be to rethink what you are actually trying to do, since I suspect there is a much simpler way to achieve the desired end result. Evo2. |
you need to use backticks instead of ' :
foreach line (`cat abc.lst`) use tcsh -x -v <your script> to see what's happening |
I have used backticks in my script. Issue isn't with ticks for me. I
Issue is with "xyz" variable which is in $line. If i write my script as below foreach line (`cat abc.lst`) cat $xyz/list/source/abcxyz.f >> temp1 end Then it works. But i need to use $line as my real time need may be with file containing multiple lines. Thanks Praveen |
so you need double evaluation:
eval cat $line >> temp1 but using eval can be dangerous and not suggested at all. as it was mentioned there should be a much better/simpler way to do that |
All times are GMT -5. The time now is 04:57 AM. |