When I redirect the output of a script within a script, I expect the redirection to be applied to the called script as well as the program called within it.


./B 2>> error.log



Running A outputs to stdout and stderr. I'd expect stderr to go to error.log instead. Apparently I am wrong.

Why isn't the output of B redirected, when called from A?

How can I make sure that the subscript's (B) and the executable's output are redirected as A is trying to attempt?

Here is my actual test case:


./other_script.sh 2>> error.log



redirection compiled from redirection.c with gcc -o redirection redirection.c:

#include <stdio.h>

#define NB_LOOPS (10)

int main(void)
    int i;
    for (i = 0; i < NB_LOOPS; ++i) {
        fprintf(stdout, "stdout %d\n", i);
        fprintf(stderr, "stderr %d\n", i);
    return 0;
  • May be source ./B 2>> error.log in A helps – Costas May 20 '15 at 9:58
  • 1
    FWIW - It writes the "stderr n" lines` to error.log for me - using your compiled c program and scripts as per your examples. – Peter.O May 20 '15 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.