Need help setting up a script to change date and time Mac OS Catalina
Solution 1:
I could get this to work by piping the password to sudo from a file instead of using echo:
sudo -S date 0101000120 < ~/passwd.txt
I'm not sure what security implications this has though, but it feels wrong ...
If you're after a quick and dirty solution then this will do it, however as per nohillside's comment, here are some instructions to run sudo commands without requiring a password. These suggestions work for me on Mojave in iTerm2 and terminal.