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’
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Rumca
  • 709
  • 1
  • 8
  • 17
  • 2
    Hauke Laging's answer gives a workaround. See [this answer](http://unix.stackexchange.com/questions/74484/usr-bin-env-zsh-no-such-file-or-directory/74488#74488) for why your attempt failed: the shebang mechanism under Linux only allows a single argument. – Gilles 'SO- stop being evil' Feb 22 '14 at 23:35

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
  • 88,146
  • 18
  • 125
  • 174
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
  • 944
  • 10
  • 19