in reply to Re^2: open with pipe
in thread open with pipe

You have to work with an unknown shell. Many shells behave according to POSIX, others don't. You don't know what shell you get. You can't write reliable code this way.

It's sh except on Windows, and that's easy to check.

Replies are listed 'Best First'.
Re^4: open with pipe
by afoken (Chancellor) on Aug 01, 2010 at 19:05 UTC

    Sure it's /bin/sh, but what shell do you get there?

    Most Linux systems have a symlink to /bin/bash there, most times giving you a bash v1, v2, v3 or v4. Newer Debian and Ubuntu versions have a symlink to /bin/dash, which is a Debian modified ash. Other Linux distributions symlink to the original ash or the busybox implementation of ash. Some BSDs have ash, others pdksh. Solaris has a bourne shell there. Some Mac OS X versions have a zsh there. Other operating systems have a korn shell as /bin/sh.

    See http://www.in-ulm.de/~mascheck/various/shells/ and the pages linked from there for the ugly details, especially http://www.in-ulm.de/~mascheck/bourne/ for the bourne shell variants, and http://www.in-ulm.de/~mascheck/various/ash/ for the ash family.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      Wow! I suppose some of those shells are incompatible with the bourne shell?

        I think so.

        The bourne shell itself already has so many variants that I would not bet on anything more complex than '/path/to/program' 'arg1' 'arg2' ... 'argN' to work reliably across all those shells, and even that only for small values of N, and not for the entire charset. Especially not on systems from the last century.

        Even "$@" has two implementation variants that can cause trouble, leading to the cryptic ${1+"$@"} in perlrun.

        There are Portability Notes for shell programming, lots of them.

        Things get worse outside the Unix world, especially with Microsoft systems (DOS, Windows, OS/2). I learned from experience that it is often easier to get out of the shell as fast as possible and let perl do the job without any support from the shell beyond passing parameters to perl.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)