Requirements Description :
Today, in the process of changing the password by using the echo combination passwd, there is an error that cannot be modified.
The error is as follows :
[Email protected] ~echo"[email protected]! " passwd --stdin mytest-bash:! " : Event not found
Error Analysis :
After finding the command find the exclamation mark! There are special definitions in Linux that can be used to perform historical commands or as a logical negation, so the exclamation mark is a special character that you want to use as a normal character and must be escaped.
Problem Handling :
1. Escape by escaping character pair!
Echo " [Email protected]\! " [email protected]\!]
Note: It is found that the output is more. So, this method is not correct.
Use single quote output after 2.echo
Echo ' [Email protected]! ' [email protected]!
[Email protected] ~]# echo ' [email protected]! \ # %‘
[Email protected]! \ # %
Note: If single quotation marks are used, the output string is as-is, not escaped, and does not take the value of the variable
3. Change the user password again via Echo and passwd
Echo '[email protected]! ' passwd -- for user mytest. passwd su -su -
Note: This will allow you to include this symbol in your password!
4. After testing, if you use double quotes output character The last one is an exclamation mark! will be error, if there is a space behind will not error
Echo " " #后面有空格, you will be able to output an exclamation mark, so if the exclamation mark is the last one to receive event events, but there are spaces in the password. [email protected]! echo"[email protected]! "-bash:! " : Event not found
5. After testing, echo directly followed by the character can not be placed in single quotation marks or in double quotation marks
Echo passwd -- for user mytest. passwd : All authentication tokens updated successfully. su -su -
Note: Same effect, no single quotation mark, no double quotation mark is used here.
Document creation time: July 2, 2018 13:28:20
Document Modification 1: Add 4 to this test, use double quotation marks, and then add a space after the number to output, but the password does not meet the expected requirements. Time: July 2, 2018 13:35:08
Document Modification 2: Add 5 of the content, Echo does not use a single quotation mark, and does not use double quotation marks for the output of an exclamation mark. Time: July 2, 2018 13:43:44
How to use the Echo output in Linux! (exclamation mark)? -bash:! ": Event not found