Script that reads input from terminal. How to tell the script to print to both tty and stdout in case it is called with a stdout redirection?
0
votes
1
answer
95
views
I have a script which asks users for input in the terminal, therefore in case the script is called with stdout redirected to a file, the user has no context on the prompt. So I would like to duplicate stdout to both sites.
The script outputs a calculus so it still makes sense to allow stdout redirection.
But if stdin is provided (kind of yes command or non-interactive context like a cron), it makes sense the output IS perfectly allowed to not being required in the tty.
So I would like to do some kind of logic like:
If (test -t 0 && ! test -t 1);
// Tell stdout to print everything to tty as well
Is this possible? Or is it fundamentally inappropriate?
Asked by Whimusical
(285 rep)
Feb 24, 2024, 06:52 PM
Last activity: Feb 26, 2024, 01:39 PM
Last activity: Feb 26, 2024, 01:39 PM