Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)
I wanted to vary my password in my Unix user using the shell script, but without being prompted to enter the old password.

That means i would like to supply the old and new password in my shell script itself, such during the prompt it'll read it from the script file.

1 Answer

0 votes
by (36.8k points)
edited by

Use the below command: 

$> echo -e -n "oldpasswd\nnewpasswd\nnewpasswd" | passwd

Or you can write the file with your passwords

oldpassword

newpassword

newpassword

and use the following command: $> passwd < file

The pipe and redirection operators are replacing the quality input with either the content of the file redirected, either the output of the command piped.

Want to be a Linux expert? Come and join this Linux course

Do check out the video to understand Linux from scratch

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...