/********************************************************************* * Author : Samson * Date : 07/03/2014 * Test platform: * 3.11.0-12-generic #19-Ubuntu * GNU bash, version 4.2.45 * *******************************************************************/
Redirect the content of stdin to the test file (to overwrite the file content, if this file does not exist, it is created), and write when stdin contains EOF:
Ufo @ ufo:/tmp $ cat> test <EOF
> This is first line
> This is second line
> This is thrird line
> This is fourth line
> EOF
Ufo @ ufo:/tmp $ cat test
This is first line
This is second line
This is thrird line
This is fourth line
Redirects the content of stdin to an existing test file by adding it, and writes the content when stdin contains EOF:
Ufo @ ufo:/tmp $ cat> test <EOF
Bash: EOF: No file or directory
Ufo @ ufo:/tmp $ cat> test <EOF
> This is five line
> This is sixth line
> EOF
Ufo @ ufo:/tmp $ cat test
This is first line
This is second line
This is thrird line
This is fourth line
This is five line
This is sixth line
Note: The above EOF can be another string you want.