There are some commands which result in different results in bash when typed into a window vs. when stored in a file and run with the "." operator.
Example, 3 lines in "commands3.txt"
date > 1.killme ; sleep 5 ; date >> 1.killme
date > 2.killme ; sleep 5 ; date >> 2.killme
date > 3.killme ; sleep 5 ; date >> 3.killme
Type the first line into a bash shell and the resulting "1.killme" file has two lines with two time stamps. However do:
. commands3.txt
And each line has just one time stamp (the second, which overwrites the first.)
Change the file to this:
date > 1.killme ; echo 1; sleep 5 ; date >>1.killme; echo 2
date > 2.killme ; echo 1; sleep 5 ; date >>2.killme; echo 2
date > 3.killme ; echo 1; sleep 5 ; date >>3.killme; echo 2
and do the dot file method again and this time each file will have both time stamps. Change it to this:
date > 1.killme ; sleep 5 ; date >>1.killme;
date > 2.killme ; sleep 5 ; date >>2.killme;
date > 3.killme ; sleep 5 ; date >>3.killme;
and do
. commands3.txt
And the files will again contain both time stamps, but at the expense of emitting ": command not found..." on every line.
If this is as it should be, can somebody please explain why bash is doing this?
bash 4.2.46, date 8.22, on Centos 7
Thanks
EDIT: as the answers said it would be, there were embedded \r in the commands3.txt file. Apparently cut/paste into the xterm silently removes those somehow.
Thanks all.