Quote:
Originally Posted by
phunkypants
I have a text file called file1 which contains the text: "ls -l"
When I enter this command:
bash < file1 > file1
file1 gets erased. However if I enter this command:
bash < file1 > newfile
the output from "ls -l" is stored in newfile. My question is why doesn't file1's text ("ls -l") get replaced with the output of the ls -l command?
if we look at how the second version works:
1. bash will create a empty file called newfile, ready to accept the output from your commands.
2. bash will open the file1 to get input.
3. bash will run the ls -al that it found in file1.
4. the output of ls -al is sent to the output file called newfile.
so if we then look at the "broken" first version:
1. bash will create an empty file called file1. (over writing your "ls -al" command)
2. bash will open the file1 (now empty)
3. bash will find nothing to do.
4. bash will send the output of nothing to the new file called file1