I am trying to use read, to read from a file descriptor, like so:

read -u fd

as in in this link.

Here is the code I am using in a bash script:

echo " parent message => $MESSAGE"  >&2

The exact error message:

read: Illegal option -u

Anyone know what this could possibly be about?

  • the file descriptor is definitely defined by NODE_CHANNEL_FD, so that shouldn't be part of the problem Commented Dec 9, 2016 at 3:19
  • if I run the bash script with the bash executable, instead of the sh executable, the error goes away. But what confuses me, is that at the top of the of the shell script, is the hashbang - #!/usr/bin/env bash, which I thought meant to tell sh to run the file with bash.... Commented Dec 9, 2016 at 3:21
  • Among modern Bourne-like shells, only bash. ksh and zsh support read -u <fd_num>.
    – cuonglm
    Commented Dec 9, 2016 at 3:22
  • thanks, yeah, so any idea why /usr/bin/env might not be defined on my system? that's why this is not working AFAICT. The shebang won't work, because /usr/bin/env is not even a directory...I am on Ubuntu 16.04 Commented Dec 9, 2016 at 3:24
  • Not sure why /usr/bin/env is relevant here. Ubuntu /bin/sh is linked to /bin/dash, so you may want to use /bin/bash instead.
    – cuonglm
    Commented Dec 9, 2016 at 3:25

1 Answer 1


The error message suggests that you are in fact not executing the script using bash.

Either make the script executable and add a proper #!-line on the first line of the script, e.g.


Or, execute the script with bash explicitly:

$ bash script.sh

You should treat sh and bash as implementing separate languages, and use the correct interpreter for the script you're writing. In this case, you're using read with the -u option. This is originally a ksh extension to the standard read specification, and it's also implemented in bash and zsh. Hence, you need to run the script with bash, zsh or ksh.

How to know when to use sh and when to use bash or some other shell? It's simple, you learn the way sh works and what other features other shells add.

  • 1
    -u was initially a ksh extension. Also supported by zsh and bash. One can always use read <&"$fd" in standard sh to get the same effect. Commented Sep 4, 2017 at 11:27
  • @StéphaneChazelas You're better at shell history than what I am...
    – Kusalananda
    Commented Sep 4, 2017 at 12:02
  • 1
    There are very few features that are native to bash. Most for come from ksh and csh, a few from zsh and mksh. If in doubt, you can always check the ksh86 or ksh88 (here ksh88i, but there has been little evolution in ksh88 feature-wise since 1988) man pages. If it's not in ksh88, it may come from ksh93, but then, you'd need to check if it was added in bash or ksh93 first. Commented Sep 4, 2017 at 12:59
  • @StéphaneChazelas Thanks! I appreciate the pointers.
    – Kusalananda
    Commented Sep 4, 2017 at 13:04

You must log in to answer this question.

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