Sample Header Ad - 728x90

pipe password to `sudo` and other data to `sudo`ed command

10 votes
3 answers
31714 views
Both of these commands work: (note the -S in sudo tells sudo to read the password from stdin). echo 'mypassword' | sudo -S tee -a /etc/test.txt &> /dev/null echo -e '\nsome\nmore\ntext' | sudo tee -a /etc/test.txt &> /dev/null Now I would like to combine the two, i.e. achieve everything in just one line. But, of course, something like this doesn't work: echo -e '\nsome\nmore\ntext' | echo 'mypassword' | sudo -S tee -a /etc/test.txt &> /dev/null What would work? Thanks:) - Loady PS: Minor unrelated question: is 1> identical to > ? I believe they are..
Asked by Anthony Webber (455 rep)
Sep 12, 2017, 12:46 PM
Last activity: Aug 10, 2024, 08:42 PM