0

I have mentioned below cmd on top of the script

exec > >(tee -a "$log_file") 2>&1
# (all remaining script part here)

The shell script is user interactive, so I want the inputs given by user are also to be redirected in same file. How this can be achieved?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • The user input goes into the commands reading the input, not into the log file. If you want to capture the whole session, run it with the `script` utility. – Kusalananda Apr 08 '21 at 06:41
  • can you show with example please – user465681 Apr 08 '21 at 07:16
  • Install the `script` utility, if it's not already installed, then run `script -c ./myshellscript.sh` (where `myshellscript.sh` is the name of your script). You would not need the `exec` command in the script. – Kusalananda Apr 08 '21 at 07:18
  • Similar, but placing input/output redirections outside the script: https://unix.stackexchange.com/q/639326/315749 (plus a `script` example). – fra-san Apr 08 '21 at 08:56

0 Answers0