2

I want to use the line below to change a password. When I put actual values instead of variables, the command works perfectly.

echo -e "$sshpass\n$sshpass | (passwd --stdin root)"

$sshpass is a variable containing a password.

I tried the following to make commands work with no luck:

echo -e "/$sshpass\n/$sshpass | (passwd --stdin root)"
echo -e "$sshpass\n$sshpass | (passwd --stdin root)"
echo -e "'$sshpass'\n/'$sshpass' | (passwd --stdin root)"

How can I make it work?

1
  • Are you sure the first one works when you use echo -e "xyz\nxyz | (passwd --stdin root)"? It shouldn't change the password. Commented Aug 18, 2013 at 15:25

2 Answers 2

5

Do not include the rest of the pipeline in the double quotes. The subshell (parentheses) is not needed.

echo -e "$sshpass\n$sshpass" | passwd --stdin root
Sign up to request clarification or add additional context in comments.

Comments

1

Use this:

echo -e "$sshpass\n$sshpass" | passwd --stdin root

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.