Have you tried to compile something that wasn’t in the repositories, or otherwise run a shell script, and gotten this error?
mark@atlantis:~/code/mpeg4ip-1.5.0.1$ ./bootstrap
dir: .
SDL appears to be installed
./bootstrap: 76: Syntax error: Bad fd number
This “Bad fd number” error occurs because Ubuntu Edgy uses dash as /bin/sh. In Ubuntu 6.06 “Dapper Drake” and earlier versions used bash instead, which ran scripts in a special backwards-compatibility mode that wasn’t truly backwards compatible (i.e. some bash-specific code was still accepted, even though it wasn’t part of the POSIX 1003.2 and 1003.2a specifications for shells). Ubuntu Edgy is the first version of Ubuntu that symlinks /bin/sh to /bin/dash instead of /bin/bash. The packages in the repositories have been checked for compatibility, but this may still cause problems with improperly-written third-party shell scripts.
Confused yet? There’s a simple solution: run the script through bash yourself.
mark@atlantis:~/code/mpeg4ip-1.5.0.1$ bash bootstrap
If you’re developing your own shell script and your users are reporting this error to you, you should change the first line of your script to #!/bin/bash, since you’ve been relying on bash-specific extensions without realizing it. Or better yet, take the time to learn what those extensions are, and fix them so your script works in POSIX-compliant shells. You can manually install dash and test compatibility by changing the first line of your script to #!/bin/dash, then change it back to #!/bin/sh once everything works again. I did this with my podencoder script and found a few surprises.
This tip has been brought to you by someone who knows just enough shell scripting to be dangerous.
Further reading:
§
You’re running edgy already? Blimey.
From the Dash as /bin/sh Ubuntu Wiki Page: The default user shell (that set by adduser) would remain as /bin/bash, as would the shell of existing accounts including root.
Did you create a new account when you installed Edgy, or does that mean it doesn’t work as described?
Most of the scripts use #!/bin/sh and on Edgy that is a link to /bin/dash so it does not interfer with the shell the user has only for scrpting.
I typically manually run bash for shell scripts, except for a few of my own private scripts that require csh. However, when installing a package, there could be scripts that explicitly launch other scripts by calling sh.
What shell construct raises “Bad fd number” ? And why?
The particular script where I noticed the problem was attempting to redirect FAAC’s help output (printed to stderr, I believe) to a file.
faac --help >&faac_help
This is the line that caused the “Bad fd number” error, but I don’t know enough about shell scripting to know why.
— Mark ![]()
‘>& file’ is a csh way to redirect both stdout and stderrto a file, and bash allows the same construct.
sh uses >& in a more restrictive manner. When sh sees >&, it accepts only a file descriptor number after the >& and freaks out when it sees a non-number.
The sh redirection of both stdout and stderr to a file is ‘> file 2>&1′, meaning redirect stdout to file and then redirect sdterr to stdout.
I am no longer accepting public comments on this post, but you can use this form to contact me privately. (Your message will not be published.)
§
© 2001–9 Mark Pilgrim