When I use erase-buffer function to clean all content of *eshell* buffer. It shows test is read only.
I find the answer to "How to clear the *shell* buffer ?" Using the following function replace.
(defun eshell/clear ()
"Hi, you will clear the eshell buffer."
(interactive)
(let ((inhibit-read-only t))
(erase-buffer)
(message "erase eshell buffer")))