The 3>&-
close the file descriptor number 3 (it probably has been opened before with 3>filename
).
The 2>&1
redirect the output of file descriptor 2 (stderr) to the same destination as file descriptor 1 (stdout). This dies call dup2()
syscall.
Для получения дополнительной информации о перенаправлении дескриптора файла обратитесь к файлам bash (`man bash). Они плотные, но великие.
Для вашего скрипта я сделал бы это так:
#!/bin/bash
if [[ -z $recursive_call ]]; then
recursive_call=1
export recursive_call
"$0" "[email protected]" | tee filename
exit
fi
# rest of the script goes there
Однако он теряет код выхода из сценария. В bash есть способ получить его, я думаю, но я не могу его запомнить.