Redirecting/Capturing inputs supplied in interactive script

Hello

Is it possible to redirect standard input into a file in an interactive script like we do for standard out and input using &2 and &1.

Enter source :
hi
Enter destination :
bye

In the log i can see like this when I am using

script.sh 2>&1 | tee file

Enter source :
Enter destination :

As of now I am using echo to log the user inputs.

you have to use the named pipes for this..

 
mkfifo out.pipe err.pipe
exec 3>&1 4>&1
tee Menu_`date +"%d-%m-%Y"`.log < out.pipe >&3 &
pid_out=$!
exec  1>out.pipe
tee Menu_`date +"%d-%m-%Y"`.err < err.pipe >&4 &
pid_err=$!
exec  2> err.pipe
rm out.pipe err.pipe
 
# your interactive script comes here
 
exec 1>&3 3>&- 2>&4 4>&-
wait $pid_out
wait $pid_err
1 Like

Thanks . But looks complicated for for my level of knowledge.

Unfortunately there is no easy way :slight_smile: