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’
1
  • 2
    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. Feb 22, 2014 at 23:35

2 Answers 2

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .