If you are looking for a quick and easily solution to changing your Linux passwd from a script, you have come to the right place. As you already know, the passwd command prompts the user to enter the desired password as well as a confirmation, but I have a solution that will change the password without these prompts.
Changing Linux Password In a Scriptable Way
echo <Desired Password> | passwd --stdin root
That’s all there is to it! No fancy bash script, no need to use Expect.