5

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’
  • 1
    Hauke Laging's answer gives a workaround. See this answer for why your attempt failed: the shebang mechanism under Linux only allows a single argument. – Gilles Feb 22 '14 at 23:35
7

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
0

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.