Description of Requirement :
In doing today in conjunction with passwd to change user passwords with the echo of the process, the error can not be modified appear.
Error as follows :
[root@testvm ~]# useradd mytest [root@testvm ~]# echo "my@test!" | passwd --stdin mytest -bash: !": event not found
Error analysis :
This command is found through the search exclamation mark! Special defined in linux, the history can be used to execute commands or as negative logic, etc. to use, so, the exclamation mark is a special character, you want the characters as ordinary characters use must be escaped.
Problem :
1.! No escape by the escape character
[root@testvm ~]# echo "my@test\!" my@test\!
Note: This output found inside on more \ Therefore, this method does not.
2.echo output later use single quotes
[root@testvm ~]# echo 'my@test!' my@test! [root@testvm ~]# echo '$my@test! \ # %' $my@test! \ # %
Note: If a single quotation marks, as it will output the string, without escaping, does not take the value of variable
3. Modify the user password and passwd echo again
[root@testvm ~]# echo 'my@test!' | passwd --stdin mytest Changing password for user mytest. passwd: all authentication tokens updated successfully. [root@testvm ~]# su - mytest [mytest@testvm ~]$ su - mytest Password: [mytest@testvm ~]$
NOTE: This password can be included in a symbol!.
4. After testing found that if you use double quote character output is the last one exclamation point! Will complain, if there are spaces behind the error will not
[root @ testvm ~] # echo "my @ test!" there is behind # spaces, you can output exclamation mark, so if the exclamation mark was the last to take the event event, but this password is also a space of. My @ the Test! [root @ testvm ~] # echo "! My @ the Test" -bash:! ": Event not found
5. After testing, echo back character can be directly connected to that is not to be placed in single quotes are not in double quotes
[root@testvm ~]# echo my@test! | passwd --stdin mytest Changing password for user mytest. passwd: all authentication tokens updated successfully. [root@testvm ~]# su - mytest [mytest@testvm ~]$ su - mytest Password: [mytest@testvm ~]$
Note: Similarly achieve the same effect, there is no single quotes and do not use double quotes.