Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
Linux Software

A Real Bourne Shell for Linux? 388

the_code_poet asks: "I'm a lead developer for a software development company, and one of my responsibilities has been writing an installer for our product (of which Linux is one of the platforms). In keeping with UNIX tradition, the installer is written in shell (thats /bin/sh), but as many of you know there is no Bourne shell for Linux - only bash. This has caused inconsistencies (mostly bugs in bash) when writing a generic UNIX sh script that works fine on commerical *NIX's." For a semi-complete list of differences between bash and sh, you will want to check out section C1 of the Bourne Again Shell FAQ. To be honest, I have yet to run into much trouble with a script starting with #!/bin/sh with /bin/bash, and I've been using the latter for years. If any of you have had problems related to this, please tell us what the problem was and how you solved it. Also: would anyone out there be interested in writing a real Bourne Shell for Linux?

"On every distro I've ever seen /bin/sh is just a soft link to /bin/bash. If bash is invoked with sh as its name (argv[0]) then its supposed to act like Bourne - but that just doesnt happen (for example: export FOO=bar is *not* valid Bourne shell syntax, you must say FOO=bar; export FOO)

Do you think that the startup scripts for most distributions would break because, even though they say
#!/bin/sh at the top, they REALLY mean #!/bin/bash?

Given that there is no real Bourne shell for Linux, and that bash has an exhorbitant file size. Quoting bash's man page, here: '...it's too big and too slow' for something that is to be used as the defacto-standard shell for scripting, do you think its a worthy venture to set out to write a small, tight, pure Bourne shell?

*asbestos disclaimer*: This has nothing to with Bash as an interactive user shell and has nothing to do with a holy war over who's favorite shell is better than whomever's."

While doing a small bit of research on this question, I noted there was another Bourn-compatible shell out there called "ash", yet it's billed as doing "some things better and some things worse than bash". Does anyone use it, and find it better than bash for their shell scripting needs?

This discussion has been archived. No new comments can be posted.

A Real Bourne Shell for Linux?

Comments Filter:
  • by Llanfairpwllgwyngyll ( 81289 ) on Saturday November 17, 2001 @07:45PM (#2579713) Journal
    It's not *quite* a non-issue.

    If you want to use sh, start with #!/bin/sh rather than #!/bin/bash - the executable notes which name you invoke it with and adjusts a couple of minor details of behaviour accordingly.
  • Re:Try this out! (Score:2, Insightful)

    by anothy ( 83176 ) on Saturday November 17, 2001 @07:54PM (#2579740) Homepage
    problems here:
    first, what's the first script to be written in, that it'll run on any unix? i guess this is easier than the general case, but still not an issue to ignore.
    also, this more than duplicates the work of writing and maintaining these scripts. you've got the install scripts twice, plus the selector script.
  • by mj6798 ( 514047 ) on Saturday November 17, 2001 @08:01PM (#2579760)
    There have been lots of different versions of the "real Bourne shell" over the years. From a practical point of view, you should have no problem writing scripts that run in bash and in whatever shell you consider "real". Stick to the POSIX specs where possible.

    However, why are you writing "installer scripts" anyway? If you want to deliver on Linux, please use the Linux packaging system. If you deliver on Solaris, please use the Solaris packaging system. Etc.

  • Re:Easy. (Score:1, Insightful)

    by Vanbo ( 75942 ) on Saturday November 17, 2001 @08:02PM (#2579765) Homepage
    Why has this been marked down to -1?

    He just gave a valid solution.

    Include the FreeBSD source to /bin/sh with your product, have a simple script compile and install it on the Linux both someplace. Have your complicated install script use the new bourne shell for installing your app.

    I am hoping it was just accidentally marked down with the thought: "Oh no, someone is telling him to install FreeBSD, better mark it down"

    This is not what the parent was suggesting. Read carefully before blindly modding down based on seeing something you don't like...
  • by aheitner ( 3273 ) on Saturday November 17, 2001 @08:14PM (#2579795)
    Yes. I did.

    And it was nonsensical.

    If he's going to complain about bash being not exactly POSIX, he's got to show an example of an incompatibility (as a decent sometime bash and ksh hacker, I can't think of one -- and I can think of one subtlety that ksh and zsh do differently than POSIX: word splitting).

    Ok. "export FOO=bar" doesn't work on a strictly-POSIX shell. But why is it bad for that to work in bash (and ksh and zsh)? How does that hurt you?

    Instead, why doesn't the article's poster come up with an example of a valid POSIX statement that breaks in bash -- that way he actually has a complaint: he did something POSIX (i.e., the standard), and bash did the wrong thing. As it stands, he's just griping.

    I mean, I agree with him -- bash is bloated and not a good choice for scripting. But that just means that scripts should be written in a shell optimized for scripting -- ksh. Or at least a minimalist straightforward POSIX shell (ash).

    But if a system wants to provide just one POSIX shell (to save space, or whatever), and if bash is going to be used by 95% of users anyhow (so is likely to be loaded anyhow), making the one POSIX shell available on the system be bash isn't a bad call. Now that doesn't excuse scripts using non-POSIX features under the name of /bin/sh. But I'd hazard to guess that 99% of the time those scripts are distro-specific in many other ways, so it doesn't really matter.

    I still have yet to see how (from anything but an efficiency perspective), this guy is finding that bash somehow makes his life harder.

    (side-point: it is annoying that you can't solve the efficiency problem by relinking /bin/sh to ksh or ash, since all the system scripts will do slightly-non-POSIX things and therefore should be specifying /bin/bash).

    ...

    I apologize for my confrontational tone. It really irks me when people propose writing things without bothering to check if the work has been done for them. I mean, come on, guys, it's Free Software. Avoiding duplication is the name of the game.
  • by Anonymous Coward on Saturday November 17, 2001 @08:16PM (#2579801)
    except on the *NIX that is growing the fastest, Linux, KDE is still include as default in every major distrobution except for RedHat. It is also default in the second largest *NIX, FreeBSD.

    Face it, gnome is dead. all of the gnome developers should switch to KDE or else their work will be at loss.
  • by aheitner ( 3273 ) on Saturday November 17, 2001 @08:28PM (#2579828)
    I apologize if my tone comes off confrontatively :-).

    I'm reacting negatively to the idiotic suggestion that people need to waste time "writing a real Bourne shell for Linux".

    If you don't like bash, there are several other shells which attempt to be POSIX. Some of them are quite strict (ash). Some are optimized for scripting (ksh).

    If you want to argue that bash sucks and should be replaced as the default system scripting shell, I totally agree. If you want to say that it sucks when scripts request /bin/sh but use bash-specific features, I agree.

    But for goodness sake, give some respect to the work that's been done.

    ...

    I did see one good post noting the bash specifics that are missing, as a POSIX shell. They really are quite minor...
  • by seebs ( 15766 ) on Saturday November 17, 2001 @08:35PM (#2579845) Homepage
    Embrace and extend. There is no way to write a script in bash and have bash warn you if you're using an extension, so they tend to creep into scripts. Embrace and extend is evil; the compatability mode should be *pure* sh, with no extensions.
  • by Anonymous Coward on Saturday November 17, 2001 @08:59PM (#2579892)
    The problem is that "/bin/sh" SHOULD be the Bourne shell, or at least a 100% Bourne-compatible shell, on UNIX systems.

    bash is not 100% compatible. If I want bash, I use #!/bin/bash, but if I use #!/bin/sh and write Bourne shell code, I expect it to not break.

    If bash is used as /bin/sh, some scripts written for Bourne shell (= /bin/sh) do not work, and that's a big problem.

    /bin/sh is the Bourne shell, /bin/bash (or /usr/bin/bash, or whatever) is bash. Asking vendors to replace /bin/sh with bash is not reasonable since bash isn't fully compatible with the Bourne shell. Asking them to include bash and install it as /usr/bin/bash however, is quite reasonable.
  • by psamuels ( 64397 ) on Saturday November 17, 2001 @10:44PM (#2580082) Homepage
    In bash you cannot do this:

    test -d "$dir" || ( echo "$dir doesn't exists"; exit 1)

    That's buggy, isn't it? The () force the 'exit 1' to occur in a subshell, so the main script doesn't exit anyway. Use {...;} instead of (...) for what you want.

    Thus, autoconf creates this kind of exit:

    What you are seeing in autoconf macros is an attempt to support every single Unix vendor shell ever released, including old versions of bash that had weird bugs since bash had not yet matured ... but also weird bugs in old versions of other shells. Are you sure the above workaround is for bash, specifically?

    [As an aside, note that the autoconf macro also directs output to two separate files, adding to its complexity. Apples to apples, etc.]

    If you are trying to do that, certainly you will have to jump through hoops.

    If you can assume bash 2.0 or above, you shouldn't really need any bash workarounds.

    Depends on what your requirements are, I guess.

  • by psamuels ( 64397 ) on Sunday November 18, 2001 @03:37AM (#2580550) Homepage
    His point is that if Linux had a real Bourne Shell, he's wouldn't have to give two shits about what distro/version/patchlevel was installed as it related to his install scripts.

    In that case, the question should have been more like "(a) why didn't someone open-source the real Bourne shell many years ago so we could have had a mature implementation of /bin/sh, or (b) why didn't Red Hat license the real Bourne shell, or (c) why did Chet not squash all the bash bugs by the time he released 1.14, so when Red Hat went to use it with RH Linux 6.1 they would have a solid sh implementation?"

    The answers are easy enough: (a) the owner of the Bourne shell didn't release it as open source for ... well, whatever reason, it's not important. The important thing is, they didn't, so what are you gonna do about it? Answer: write a new implementation. And that's what Chet and co. did for the GNU project with bash, only it was started many many years after the original sh, so until a few years ago it still had weird bugs in it. The answer to (b) is that Red Hat chose to use only open-source software for ... again, the reasons are not important here.

    As for (c), whose fault is it that a buggy bash was shipped with Red Hat Linux 6.1? Dunno - I think bash 2.0 was out and in active use by the time it shipped, but I'm not sure. And I'm not sure ash wasn't just as bad, at the time, so you can't blame Red Hat for that either.

    In summary, he (and you) are griping about what someone released a couple years ago and they (and you) are still forced to support. Nothing much can be done about it now - it's a solved problem, bash 2.x has been out for quite awhile, but you can't really make people upgrade to it. (Same goes for alternative shells like ash - they're available and they work fine, but you can't make people install them either.)

  • by Anonymous Coward on Sunday November 18, 2001 @09:57AM (#2580929)
    This has caused inconsistencies (mostly bugs in bash) when writing a generic UNIX sh script that works fine on commerical *NIX's."

    What exactly were the "inconsistencies"? How many were there? What features did they involve? I've been in the business long enough to recognize situations where my own unfamiliarity with a particular technology spanks me hard. Perhaps the original poster is finding him/herself in a similarly humbling situation?

"Experience has proved that some people indeed know everything." -- Russell Baker

Working...