0. PrefaceThis article summarizes how to use the echo command to write content to a file, such as using the ECHO directive to overwrite the contents of a file. Use the echo command to append content to a file. Use the Echo command to append tabs to the file. The basic way for Echo to output content to a file is to use the IO redirect command--">", by default the echo is output to standard output, and the > instruction is used to redirect output to a file.
1.echo Instruction Basic use method"1" Linux official User manual--echo instruction "2" input instructions get help sudo echo--help return content such as the following
How to use: echo [short options] ... [String] ... Or: The Echo long option echoes the STRING back to standard output. - N does not follow the newline character- e enable the escape function to interpret backslashes- e disables the escape function that interprets backslashes (default) --HELP displays this help information and exits --version displays the version number information and exits if-e is available, The following sequence can be identified: \ \ backslash \a ring ringtone \b \c no longer produces new output \e escape character \f Change page \ n new line \ r enter \ t horizontal tab \v vertical tab \0nnn bytes in octal number NNN (1 to 3 bits) \xhh Bytes in hexadecimal number HH (1 to 2 bits)
2. Overwrite file contentsDemo Sample script test.sh uses the > directive to overwrite the original contents of the file and enter the contents again. Creates a file if the file does not exist. #!/bin/bashecho "Raspberry" > test.txt "Operation Process" # Change permissions, scripts can run chmod u+x test.sh./test.sh "File Contents" Raspberry
3. append file Contents"Demo Sample Script" test.sh
Linux Learning notes-how to write content to a file using the echo command