Linux Cat and echo command detailed cat command is a text output command under Linux, usually for viewing the contents of a file; Cat has three main functions:1. Displays the entire file at once. $ cat FileName2. Create a file from the keyboard. $ cat>filename can only create new files and cannot edit existing files. 3. Merge several files into one file. $cat file1 file2>filecat Specific command format is: Cat [-ABEENSTTUV] [--help] [--Version] FileName Description: Connect the file string to the basic output (screen or add>FileName to another file) parameter:-N or –number by1start number of rows for all outputs-B or –number-nonblank and-n similar, except for blank lines not numbered-S or –squeeze-Blank when a blank line with more than two consecutive lines is encountered, it is substituted as a line-V or –show-nonprinting Example: Cat-N linuxfile1 >linuxfile2 The Linuxfile1 file with the line number, enter the Linuxfile2 in this file. Cat-B linuxfile1 Linuxfile2 >>Linuxfile3 Add the contents of the Linuxfile1 and Linuxfile2 to the linuxfile3 after adding the line number (blank line not added) to the file. Example: Add a line number to the Linuxfile1 file and enter Linuxfile2 in this file. Cat-N linuxfile1 >Linuxfile2 Add the contents of the Linuxfile1 and Linuxfile2 to the linuxfile3 after adding the line number (blank line not added) to the file. Cat-B linuxfile1 Linuxfile2 >>Linuxfile3cat/dev/NULL>/etc/test.txt this for emptying/etc/test.txt archive content in Linux shell scripts we often see similar to the cat<<EOF statements, unfamiliar children's shoes may feel strange: EOF seems to be the terminator of the file, what role does it play here? EOF is "End of File", which represents the text terminator. <<EOF (content) EOF
The first thing to note is that EOF does not have a special meaning here, and you can use foe or OOO (and of course not limited to three or uppercase characters). EOF can be replaced with other things, meaning that the content as a standard input to the combination of these two identities, you can avoid the use of multi-line echo command, and realize the results of multi-line output. Next, a brief description of several common uses and their effects: 1, cat<<eof, the EOF input character for the standard input end: 2, Cat>filename, create a file, and the standard input output to the filename file, to Ctrl + D End as input: note: There is no ' > ' on the input. 3, cat>filename<<eof, with EOF as input end, and the role of Ctrl+d: Second, use to see the example is the fastest familiar way: # cat << EOF > Test.sh> #!/bin/bash # shell script > #you Shell script writes here.> EOF result: Reference # Cat Test.sh#!/bin/bash#you Shell script writes here. Can See, the content of test.sh is the content that cat produces. The cat <<eof >test.sh content EOF---is to write the content to test.sh, and the previous content will be overwritten. EOF can be replaced with other symbols such as Eee:cat <<eee >test.sh content EEE III, other notation 1, append file # cat << EOF >> test.sh content EOF---append content to TE St.sh back, will not overwrite the original content 2, in a different way # cat > test.sh << EOF Content EOF3, EOF is just identity, not fixed # cat << HHH > Iii.txt> SDLKF Jksl> sdkjflk> asdlfj> HHH here the "HHH" replaces the "EOF" function. The result is the same. Reference # Cat Iii.txtsdlkfjkslsdkjflkasdlfj4, non-script if not in script, we can use ctrl-d to output EOF identification # cat > III.TXTSKLDJFKLJSDKFJKLkljkljkljkljlkctrl-d results: Reference # Cat iii.txtskldjfkljsdkfjklkljkljkljkljlk※ about ">", ">>", "<", "<<" and so on, See Bash's introduction for yourself. The echo command details Linux's echo command, which is very common in shell programming, and is often used when printing variable value under the terminal, so it is necessary to understand the use of the echo command to display a piece of text on the display, generally acting as a hint. The general format of the command is: Echo [-n] string where option n means that the output text is not wrapped, the string can be quoted, or it can be unquoted. When you output a quoted string with the Echo command, the string is output as it is, and when you output an unquoted string with the echo command, each word in the string is output as a string, separated by a space between the strings. Feature Description: Displays text. Syntax: Echo [-ne][string] or echo [--help][--version] Supplemental Note: Echo will send the input string to standard output. The output strings are separated by white space characters, and a newline number is added at the end. Parameters:-n do not wrap in the last line-E if the following character appears in the string, it is handled in particular, not as a general text output: \a warns, \b Deletes the previous character, \c ends with a newline symbol, \f wraps but the cursor remains in its original position; \ n Wraps and moves the cursor to the beginning of the line; \ r The cursor moves to the beginning of the line, but does not wrap, \ t inserts tab, \V is the same as \f, \ \ insert \ Character, \nnn inserts the ASCII character represented by NNN (octal); Help Display Help –version display version information
Linux Cat and Echo command details <<eof EOF