Как записать вывод скрипта в файл, но также сохранить его на экране?

используйте Scaled Mode в VirtualBox (View -> Scaled Mode), это заполнит весь экран (независимо от того, какой режим вы установили с помощью vidcontrol в вашем FreeBSD).

-4
13.09.2018, 20:06
2 ответа

Вы не уточнили, поэтому я предполагаю, что это bash-скрипт. Согласноman bash(упор мой):

exec [-cl] [-a name] [command [arguments]]
If command is specified, it replaces the shell. No new process is created. The arguments become the arguments to command. If the -l option is supplied, the shell places a dash at the beginning of the zeroth argument passed to command. This is what login(1) does. The -c option causes command to be executed with an empty environment. If a is supplied, the shell passes name as the zeroth argument to the executed command. If command cannot be executed for some reason, a non-interactive shell exits, unless the execfail shell option is enabled. In that case, it returns failure. An interactive shell returns failure if the file cannot be executed. If command is not specified, any redirections take effect in the current shell, and the return status is 0. If there is a redirection error, the return status is 1.

Таким образом, вы можете использовать замену процесса для запуска копии tee, которая ведет журнал в файл, и перенаправить свой стандартный вывод на этот tee, чтобы он печатал и регистрировался одновременно:

exec > >(tee /path/to/log-file)

Если вы также хотите захватить stderr, вам нужно объединить его с stdout:

exec 2>&1

Или просто захватите оба сразу с помощью:

exec &> >(tee /path/to/log-file)
0
28.01.2020, 05:20

Используйте tee.

script.sh < inputfile | tee logfile

0
28.01.2020, 05:20

Теги

Похожие вопросы