Skip to content
Advertisement

Sending Stata output to a logfile under Ubuntu

I write the Stata do-file and run it with a script code under the Ubuntu system.

The .sh file with the following contents:

#!/bin/bash
stata -b do mydofile.do

It will generate a log file with the name of mydofile.log after running the .sh code. My question is how to specify the path and name of this log file?

Advertisement

Answer

You could redirect stdrr and stdout (or both) of stata program to file doing like so.

#!/bin/bash

stata -b do mydofile.do &>>/path/to/mydofile.log

Here is more context:

  • 1>filename – Redirect stdout to filename.
  • 1>>filename – Redirect and append stdout to filename.
  • 2>filename – Redirect stderr to filename.
  • 2>>filename – Redirect and append stderr to filename.
  • &>filename – Redirect both stdout and stderr to filename.
  • &>>filename – Redirect both stdout and stderr and append to filename.
Advertisement