1
下面是一個解決方案,我從實測值: Create a pipe that writes to multiple files (tee)文件描述符:重定向輸入和輸出到兩個殼和日誌文件
因此下面的代碼重定向stdout和stderr到日誌文件,而在終端中顯示它們。我想知道是否有無論如何將stdin重定向到終端和日誌文件。
#!/bin/bash
LOG=./file.log
PIPE=./logPipe
mkfifo ${PIPE}
exec 3>&1 4>&2
tee -a ${LOG} <${PIPE} >&3 &
exec 1>${PIPE} &
exec 2>&1
printf "%s\n" " Enter Something "
read something
printf "%s\n" " Enter Something "
read something2
printf "\n"
printf "%s\n" " Enter Something "
read something3
mkdir ./test
mkdir ./test
mkdir ./test here
printf "$something $something2 $something3" >> something.out
終端不是一個殼。您不能在shell中顯示某些內容,但外殼可以將數據寫入到要顯示的終端。 – 2014-12-02 19:24:57
@William;使用正確的術語進行更新。 – Stelios 2014-12-02 23:24:04