Home  >  Article  >  Operation and Maintenance  >  How to solve the problem of insufficient permissions for the linux echo command and the linux echo command prompt

How to solve the problem of insufficient permissions for the linux echo command and the linux echo command prompt

巴扎黑
巴扎黑Original
2017-09-07 09:44:321985browse

The echo command of Linux is very commonly used in shell programming. It is also often used when printing variable value in the terminal, so it is necessary to understand the usage of echo. This article will introduce you to the linux echo command and the solution to the problem that the linux echo command prompts that the permissions are insufficient. Friends who are interested should take a look.

The echo command of Linux is very commonly used in shell programming and is printed under the terminal. The variable value is also often used, so it is necessary to understand the usage of echo

The function of the echo command 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

The option n means no line breaks after outputting text; the string can be quoted or No quotes. When using the echo command to output a quoted string, the string is output as it is; when using the echo command to output an unquoted string, each word in the string is output as a string, and each string is separated by a space. .

Function Description: Display text.

Syntax: echo [-ne][string] or echo [--help][--version]

Additional instructions: echo will replace the entered characters The string is sent to standard output. The output strings are separated by whitespace characters, and a newline is added at the end.

Parameters: -n Do not automatically wrap at the end

-e If the following characters appear in the string, they will be treated specially and will not be treated as ordinary

text Output:

\a emits a warning sound;
\b deletes the previous character;
\c does not add a newline symbol at the end;
\f breaks a newline but the cursor still stays at the original position ;
\n Line break and the cursor moves to the beginning of the line;
\r The cursor moves to the beginning of the line, but no line break;
\t Insert tab;
\v Same as \f;
\\ Insert \ character;
\nnn Insert the ASCII character represented by nnn (octal);
–help Display help
–version Display version information

ECHO command is familiar to everyone A subcommand of the DOS batch command, but you may not know all of its functions and usages. If you don’t believe it, take a look:

1. As a switch to control whether the command line itself is displayed when the batch command is executed. Format: ECHO [ON|OFF] If you want to turn off the display of the "ECHO OFF" command line itself, you need to add "@" before the command line.

2. Display the current ECHO setting status Format: ECHO

3. Output prompt information Format: ECHO information content The above are three common uses of the ECHO command, which everyone is familiar with and can use, but as a DOS command gold digger, you should also know the following skills:

4. Close the DOS command prompt. Type ECHO OFF in the DOS prompt state to turn off the display of the DOS prompt, leaving only the cursor on the screen. The prompt will not reappear until ECHO ON is typed.

5. Outputting a blank line is equivalent to entering a carriage return. Format: ECHO. It is worth noting that the "." in the command line must immediately follow ECHO and there must be no space in the middle, otherwise "." will be output to the screen as a prompt message. In addition, "." can be replaced by any symbol such as:;"/[/]+. In the following example, the carriage return output by ECHO. is redirected through the DOS pipe as the input of the TIME command, which is equivalent to executing the TIME command Then a carriage return is given. Therefore, when executing, the system will automatically return to the DOS prompt state after displaying the current time: C:〉ECHO.|TIME ECHO Another application example of the command outputting a blank line is : Add ECHO. to the automatic batch file so that the prompt screen originally displayed at the bottom of the screen appears at the top of the screen.

6. Question format in the reply command: ECHO reply language | command file name above. The format can be used to simplify the operation of some commands that require human-computer dialogue (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 a human-computer dialogue. Command input. The following example is equivalent to entering "Y" and pressing Enter when the command being called appears in the human-computer dialogue: C:〉ECHO Y|CHKDSK/F C:〉ECHO Y|DEL A:*.*

7.Create a new file or add file content format: ECHO file content>File name ECHO file content>>File name For example: C:〉ECHO @ECHO OFF〉AUTOEXEC.BAT Create automatic batch file C:〉ECHO C: /CPAV/BOOTSAFE〉〉AUTOEXEC.BAT appends content to the automatic batch file C:TYPE AUTOEXEC.BAT displays the automatic batch file @ECHO OFF C:/CPAV/BOOTSAFE [Commonly used]

8. The printer outputs the print content or print control code format: ECHO printer control code > PRN ECHO print content > PRN The following example is to input the print control code to the M-1724 printer. 156 means holding down the Alt key and typing 156 on the small keyboard. Similar situations can be deduced: C:〉ECHO 〈Alt〉+156〈Alt〉+42〈Alt〉+116〉PRN (enter the underscore command FS*t) C:〉ECHO 〈Alt〉+155@〉PRN (enter initialization Command ESC@) C:>ECHO.>PRN (line feed)

9. Make the horn sound C:>ECHO ^G "^G" is input with Ctrl+G or Alt+007. Enter multiple ^G to generate Multiple beeps. The method of use is to directly add it to the batch file or make a batch file call

.

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 for modifying the screen and keyboard settings. For example, if you execute the batch program below, you can define the function key F12 as the DOS command "DIR/W" and change the screen color to white characters and blue background. @ECHO”←[0;134;”DIR/W”;13p @ECHO”←[1;37;44m (Note: The input method of the “←” character in the batch file is to press Alt on the small keyboard in the editing state 27) DOS commands are the first thing people who come into contact with computers must learn. For many people, they are too familiar and too simple. In fact, they are not the case. There is rich content in these commands, which still needs to be further understood and developed by us. , if you are a thoughtful person, you will definitely find new shining points from these commands that you think you are familiar with, and make real gold.

The following will introduce to you the solution to the problem that the linux echo command prompts that the permissions are insufficient

Problem description:​​

When using the Ubuntu system, I encountered such a problem: I logged in to the system as a normal user and then executed the sudo echo "This is testPage." >/usr/local/nginx/html/index.html command. , prompting insufficient permissions.

Although I know that the echo command belongs to the permissions of the root user, I always thought that adding sudo can obtain all the root permissions. Now I realize that this is wrong. After using the sudo command, only part of the root permissions are obtained.

Solution:

1. Use the root user directly, so there will definitely be no problem;

2. The specific implementation is as follows:


sudo sh -c 'echo "This is testPage." >/usr/local/nginx/html/index.html'

**Be careful here to add single quotes to the entire echo command.

The above is the detailed content of How to solve the problem of insufficient permissions for the linux echo command and the linux echo command prompt. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn