script output name from a variable
Hello people!!
Whith an script, I want to set the name of an output file employing the name of a variable: e.g.: while read code do out=$code done < input >> $out.txt However, the name of the output file I got is '.txt'. But if i do 'echo $out', i can confirm that the variable has the value i want. I solved the issue by doing: done < input >> temp.txt cp temp.txt $out.txt rm temp.txt but this doesn't look so nice ;) any idea?? Thanks in advance! |
One solution
Code:
while read code |
I think that the file designated by the redirection gets opened before the loop starts. thus, the variable is not yet defined.
Some experiments will confirm this, but I think you've already proven it. |
pixellany has the right information. At the point of the loop starting the variable is blank and this will be when the file is opened for writing.
|
Thanks for the replies and explanations!
Yes, the variable is not defined at that stage, so the variable $out must be defined before the loop or I have to adopt the catkin's suggestion thanks! |
All times are GMT -5. The time now is 02:40 PM. |