Linux echo instruction learning

Source: Internet
Author: User
Tags set background set socket


Linux echo command learning function description: displays text. Syntax: echo [-ne] [String] or echo [-- help] [-- version] www.2cto.com. Note: echo sends the result string to the standard output by default. The output strings are separated by blank characters, and the line number is added at the end. Parameter number:-n do not wrap the line at the end-e. If the string contains the following characters, it will be specially processed and will not be used as a general text output: \ a sends a warning; \ B Delete the previous character; \ c does not end with a line break; \ f returns a line break but the cursor remains at the original position; \ n returns a line break and moves the cursor to the beginning of the line; www.2cto.com \ r move the cursor to the beginning of the line without line breaks; \ t Insert the tab; \ v is the same as \ f; \ insert \ character; \ nnn insert nnn (octal) ASCII character; -- help display help -- version display version information when echo needs to change the color, use the parameter-e format: echo-e "\ 033 [word background color; font color m string \ 033 [0 m "Example: echo-e" \ 033 [41; 36 m something here \ 033 [0 m "where 41 represents the background color, the position 36 represents the color of the word. The ascii code is the beginning and end of the color call.. \ 033 [; m ...... \ 033 [0 m makes the font red and flashes continuously # echo-e "\ 033 [31 m \ 33 [05 m please confirm whether to stop the current squid process, enter [Y/N] \ 033 [0 m "www.2cto.com or # echo-e" \ 033 [31 m \ 033 [05 m. Check whether you want to stop the current squid process, enter [Y/N] \ 033 [0 m "character background color range: 40----49 40: Black 41: Dark Red 42: Green 43: Yellow 44: Blue 45: Purple 46: dark green 47: white color: 30-----------39 30: Black 31: Red 32: Green 33: yellow 34: Blue 35: Purple 36: Dark Green 37: white =================================================== ======== ANSI control code description www.2cto.com \ 33 [0 m close all attributes \ 33 [1 m set high brightness \ 33 [4 m Underline \ 33 [5 m flashing \ 33 [7 m reverse display \ 33 [8 m blanking \ 33 [30 m -- \ 33 [37 m set foreground color \ 33 [40 m --\ 33 [47 m set background color \ 33 [nA cursor move n rows up \ 33 [nB cursor move n rows down \ 33 [nC cursor move n rows right \ 33 [nD cursor move n rows left \ 33 [y; xH set the cursor position \ 33 [2J clear screen \ 33 [K clear content from the cursor to the end of the line \ 33 [s Save the cursor position \ 33 [u restore the cursor position \ 33 [? 25l hide the cursor \ 33 [? The 25 h echo command for displaying the cursor www.2cto.com Linux is very common in shell programming and often used to print the variable value under the terminal, therefore, it is necessary to understand the echo usage. The echo command function is to display a piece of text on the display, which generally serves as a prompt. The general format of this command is echo [-n] string, where option n indicates that the output text is not wrapped after the line break; the string can be enclosed by quotation marks or without quotation marks. The ECHO command is a sub-command of DOS batch processing commands that everyone is familiar with, but you may not know all of its functions and usage. Do not believe it. Look: 1. the switch format that controls whether batchcompute commands display the command line itself during execution: ECHO [ON | OFF] If you want to disable the display of the "echo off" command line itself, add "@" to the front of the command line. 2. display the current ECHO setting status format: ECHO 3. output prompt information format: the ECHO information content is the common usage of the ECHO command. It is also familiar and useful. However, you should also know the following skills as a doscommand gold miner: www.2cto.com 4. close the doscommand prompt and type echo off at the DOS prompt. You can close the display of the DOS prompt so that only the cursor is left ON the screen until you type echo on. 5. empty output line, which is equivalent to entering a carriage return format: ECHO. it is worth noting that ". "There must be no space in the middle of the ECHO, otherwise". "Will be output to the screen as a prompt. In addition, "." can be replaced by any symbol, such as:; "/[/] +. In the following example, the ECHO. Output carriage return is switched to the input as the TIME command through the DOS pipeline, which is equivalent to a carriage return after the TIME command is executed. Therefore, after the current time is displayed, the system automatically returns to the DOS prompt status: C:> ECHO. | another example of the time echo command output empty line is: ECHO. add it to the automatic batch processing file so that the prompt screen originally displayed at the bottom of the screen appears at the top of the screen. 6. the FORMAT of the answer command: ECHO | command file name the above FORMAT can be used to simplify some commands that require human-machine interaction (such as: CHKDSK/F; FORMAT Drive:; del *. *). It uses the DOS pipeline command to use the preset reply language output by the ECHO command as the input of the man-machine conversation command. The following example is equivalent to entering "Y" press Enter: C:> echo y | CHKDSK/f c:> echo y | del a: * in the case of A human-machine conversation :*. * 7. create a new file or add the file content format: ECHO file content> file name example: C:> ECHO @ echo off> AUTOEXEC. BAT creates an automatic batch file C:> echo c:/CPAV/BOOTSAFE> AUTOEXEC. BAT adds content to the automatic batch processing file C: type autoexec. BAT displays the automatic batch processing file @ echo off c:/CPAV/BOOTSAFE 8. print content to the printer or print control code format: ECHO printer control code> prn echo print content> PRN The following example is to input a print control code to the M-1724 printer. <Alt> 156 press and hold the Alt key and type 156 on the keypad. Similarly, the push is as follows: C:> ECHO <Alt> + 156 <Alt> + 42 <Alt> + 116> PRN (enter the underline command FS * t) C:> ECHO <Alt >+ 155 @> PRN (enter the initialization command ESC @) C:> ECHO.> PRN (line feed) www.2cto.com 9. to make the horn sound C:> ECHO ^ G "^ G" is input using Ctrl + G or Alt + 007, multiple ^ G input can generate multiple sounds. You can directly add it to a batch file or call it as a batch file. 10. Execute the ESC control sequence to modify the screen and keyboard settings. We know that the DOS Device Driver ANSI. SYS provides a set of ESC control sequences used to modify the screen and keyboard settings. If you execute the following batch processing program, you can define the function key F12 as the DOS command "DIR/W" and change the screen color to the blue background of the white character. @ ECHO "values [0; 134;" DIR/W "; 13 p @ ECHO" values [1; 37; 44 m (note: in the batch processing file, the "batch" character is entered by pressing 27 on the Alt keypad in the editing status. ------------ Shell socket # include <netdb. h> # include <sys/socket. h> # include <errno. h> www.2cto.com # include <stdio. h> # include <unistd. h> # define ECHO_PORT 8080 # define MAX_CLIENT_NUM 10 int ma In () {int socketfd; socketfd = socket (AF_INET, SOCK_STREAM, 0); // aga: create server socket for listening if (socketfd =-1) {printf ("errno = % d", errno); exit (1) ;}else {printf ("socket create successfully"); www.2cto.com} struct sockaddr_in sa; bzero (& sa, sizeof (sa); sa. sin_family = AF_INET; sa. sin_port = htons (ECHO_PORT); sa. sin_addr.s_addr = htons (INADDR_ANY); // aga: set socket port and ad Dress bzero (& (sa. sin_zero), 8); if (bind (socketfd, (struct sockaddr *) & sa, sizeof (sa ))! = 0) // aga: bind socket with socket address {printf ("bind failed"); printf ("errno = % d", errno ); www.2cto.com} else {printf ("bind successfully");} // aga: after successfully binding, begin to listen! If (listen (socketfd, MAX_CLIENT_NUM )! = 0) {printf ("listen error"); exit (1); www.2cto.com} else {printf ("listen successfully");} int clientfd; struct sockaddr_in clientAdd; // aga: client socket address char buff [101]; www.2cto.com socklen_t len = sizeof (clientAdd); int closing = 0; while (closing = 0 & (clientfd = accept (socketfd, (struct sockaddr *) & clientAdd, & len)> 0) // aga: listening socket waits for accepting client connection {Send (clientfd, "connect successfully! ",); Int n; while (n = recv (clientfd, buff,)> 0) // aga: after connection established, server begins to recvive msg www.2cto.com {printf ("number of receive bytes = % d", n); write (STDOUT_FILENO, buff, n); send (clientfd, buff, n, 0); buff [n] = ''; if (strcmp (buff," quit ") = 0) {break;} else if (strcmp (buff," close ") = 0) {closing = 1; printf ("server is closing"); www.2cto.com break ;}} close (clientfd);} close (socketfd); return 0 ;}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.