user2650277
user2650277

Reputation: 6739

Using echo in Bash with variable

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?

Upvotes: 2

Views: 235

Answers (2)

Jonathan Leffler
Jonathan Leffler

Reputation: 753870

Use this:

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

Upvotes: 1

choroba
choroba

Reputation: 241888

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

Upvotes: 5

Related Questions