7

I need my script to be executed with stdbuf -i0 -o0 -e0 otherwise user will wonder why there is no output (becuase of pipe buffer). How can I acheive it?

#!/usr/bin/stdbuf -i0 -o0 -e0 /bin/bash

results in

/usr/bin/stdbuf: invalid mode ‘0 -o0 -e0 /bin/bash’
Rumca
  • 719

2 Answers2

10

Usually there is no need to unbuffer the whole script. This is necessary with certain programs only.

But if you want to do it that way you can simply call the script from itself:

#! /bin/bash

if [ yes != "$STDBUF" ]; then
    STDBUF=yes /usr/bin/stdbuf -i0 -o0 -e0 "$0"
    exit $?
fi
Hauke Laging
  • 90,279
1

Appears there are two suboptimal solutions:

Suboptimal at least when you provide input to command. Otherwise they might be both ok. script records your input and unbuffer just doesn't let you input properly. YMMV

akostadinov
  • 1,048