You can make unzip
read input from /dev/null
by redirecting its standard input:
unzip my_file.zip -d /var/tmp/my_dir < /dev/null
Another way to do this is with cat
:
cat /dev/null | unzip my_file.zip -d /var/tmp/my_dir
That is slightly less efficient, since it starts another process (cat
), but it’s perhaps easier to read. There are endless arguments about whether using cat
in this way is a bad idea.
If a program asks for a password and input file redirection doesn’t stop it from prompting you, then it gets trickier. Programs sometimes open your terminal directly using /dev/tty
, rather than relying on standard input and output. In that case, you can use expect
to send input to the program. I don’t know how to use expect
, so I can’t provide a sample script. Or you can see if there is a way to prevent your program from asking for a password.