what does "exec 5>>foobar.txt" do?

925
user322908

What does the shell command

exec 5>>foobar.txt 

do? I can't google it for obvious reasons, and otherwise not sure where to start looking.

-1

2 ответа на вопрос

3
techraf

The command in question redirects file descriptor 5 to a file foobar.txt.

As for "where to start looking" - this answer is a very good starting point.

Точнее говоря, новая оболочка создается для замены текущей оболочки, но с любыми записями в дескриптор файла `5`, добавляемый в файл с именем` foobar.txt` в текущем каталоге. Любая программа, ожидающая завершения оболочки, будет ожидать новую оболочку и получит статус ее возможного выхода. AFH 8 лет назад 2
0
glenn jackman

As others have said, it opens a file descriptor to append to the named file.

You would use this file descriptor like this:

echo "hello world" >&5 date >&5 while read line; do some_transformation; done < input_file >&5