When I run a command with sudo like the following, subsequent sudo commands will not ask for a password anymore.
sudo ls
But this still runs ls. If I don't want to run any command at the beginning, but just stop subsequent sudo commands from asking a password later on. Is there a way to do so?
sudo echo -nprobably is a way but it is not very elegant. – user1424739 Feb 25 '21 at 15:36sudo trueis better. – user1424739 Feb 25 '21 at 15:43sudo truebefore all the parts of the script that cause meaningful output so it doesn't break the output format. – JoL Feb 26 '21 at 22:49sudoinside a script, you would simply run the script withsudo. See How do I run a 'sudo' command inside a script?. – terdon Feb 27 '21 at 17:34sudowhen calling the script. The script I was thinking of where I use sudo inside it has a formality almost like a shell alias. Also, I said "script" in my original comment to be more relatable, but where I've actually usedsudo trueis actually interactively. It happens often that I build one-off loops in the shell of the formfor x in ...; do echo "=== $x"; sudo .... Having the sudo prompt come after the header is irksome, so I runsudo truebefore or writesudo true; for ..– JoL Feb 28 '21 at 19:35