Which can be use which it!
method one,
echo -e "newpwd\nnewpwd" | (passwd root)
Method Two,
echo "newpwd" | passwd root --stdin > /dev/null 2>&1
Method three,
# If the password is included in $ characters, use a backslash (\) escape
echo root: newpwd123 \ $ | chpasswd
Openwrt | openwrt compile time, how to specify the root password
CAT / etc / Shadow
root: $ 1 $ HSk7yPlb $ 6cPCTE8gYv2AxBvGdwCgS /: 17949: 0: 99999: 7 :::
package/base-files/files/etc/shadow
Reference:
https://stackoverflow.com/questions/714915/using-the-passwd-command-from-within-a-shell-script