dive into mark

You are here: dive into markArchivesSeptember 2006‘Bad fd number’ error in Ubuntu 6.10 (Edgy Eft)

Tuesday, September 19, 2006

‘Bad fd number’ error in Ubuntu 6.10 (Edgy Eft)

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:

Filed under , , , , , ,

7 comments

  1. You’re running edgy already? Blimey.

    Comment by Stuart Langridge — Wednesday, September 20, 2006 @ 2:58 am

  2. 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?

    Comment by Nicolas Chachereau — Wednesday, September 20, 2006 @ 4:05 am

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

    Comment by 2tone — Wednesday, September 20, 2006 @ 8:18 am

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

    Comment by W^L+ — Wednesday, September 20, 2006 @ 8:00 pm

  5. What shell construct raises “Bad fd number” ? And why?

    Comment by Nilton Volpato — Friday, September 22, 2006 @ 11:47 am

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

    Comment by Mark — Friday, September 22, 2006 @ 4:17 pm

  7. ‘>& 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.

    Comment by Matthew Ernest — Saturday, September 23, 2006 @ 10:10 pm

Respond privately

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



Recent Stuff For You, Special Price Stay Here
  • Greasemonkey Hacks
Good Stuff Buy The Cow Go Away
Dive Into Python
Powered by Google Drink The Milk Don't Steal

 

posts / comments
© 2001-8 Mark Pilgrim