|
Home > Archive > Unix Shell > February 2007 > Redirection specs/syntax for POSIX
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Redirection specs/syntax for POSIX
|
|
| sp_mclaugh@yahoo.com 2007-02-16, 7:16 pm |
| Hi,
If I want to write my own shell, and have it be POSIX-compliant, is
there a standard regarding what types of syntax I have to support for
standard IO redirection? For example, the usual/common way to redirect
input and output of cat might look like:
cat <inFile >outFile
I think every shell supports switching the order of inFile and
outFile, at least. But what about something like this:
<inFile >outFile cat
<inFile cat >outFile
>outFile cat <inFile
I tried the above on Bash, and they work fine. But is it standard? I
know it's a (very) pedantic question, but I can't seem to find any
documentation on it.
----------------------
Oh, and to make it slightly more interesting, what if you throw pipes
into the picture? In other words, if the same line includes both
redirection and (multiple) pipes... is there a "standard" way to
handle how to behave if:
- the input redirection isn't placed after the first command
- the output redirection isn't placed at the very end
(either one could be at the beginning, end, or mixed in the middle)
Putting the redirection in the middle would be awful style by the
user, but... I guess I'd still like to have some shred of predictable
behavior for such users.
| |
| Barry Margolin 2007-02-17, 1:22 am |
| In article <1171656244.565863.255690@a75g2000cwd.googlegroups.com>,
sp_mclaugh@yahoo.com wrote:
> Hi,
>
> If I want to write my own shell, and have it be POSIX-compliant, is
> there a standard regarding what types of syntax I have to support for
> standard IO redirection?
Is this a trick question? If you want to be POSIX-compliant, then by
definition you have to conform to the POSIX standard? Did you not
realize that this is what "POSIX" is?
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| sp_mclaugh@yahoo.com 2007-02-17, 1:22 am |
| On Feb 16, 9:04 pm, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article <1171656244.565863.255...@a75g2000cwd.googlegroups.com>,
>
> sp_mcla...@yahoo.com wrote:
>
>
> Is this a trick question? If you want to be POSIX-compliant, then by
> definition you have to conform to the POSIX standard? Did you not
> realize that this is what "POSIX" is?
I guess I phrased the question poorly. The question should have read
more like "does POSIX specify any compliance rules regarding standard
IO redirection syntax? If so, can anyone point out what those rules
are?" Sorry for the confusion wording.
Thanks,
spmclaugh
| |
| sp_mclaugh@yahoo.com 2007-02-17, 1:22 am |
| On Feb 16, 9:04 pm, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article <1171656244.565863.255...@a75g2000cwd.googlegroups.com>,
>
> sp_mcla...@yahoo.com wrote:
>
>
> Is this a trick question? If you want to be POSIX-compliant, then by
> definition you have to conform to the POSIX standard? Did you not
> realize that this is what "POSIX" is?
I guess I phrased the question poorly. The question should have read
more like "does POSIX specify any compliance rules regarding standard
IO redirection syntax? If so, can anyone point out what those rules
are?" Sorry for the confusing wording.
Thanks,
spmclaugh
| |
| Barry Margolin 2007-02-17, 1:22 am |
| In article <1171681498.696201.292830@v33g2000cwv.googlegroups.com>,
sp_mclaugh@yahoo.com wrote:
> On Feb 16, 9:04 pm, Barry Margolin <bar...@alum.mit.edu> wrote:
>
> I guess I phrased the question poorly. The question should have read
> more like "does POSIX specify any compliance rules regarding standard
> IO redirection syntax? If so, can anyone point out what those rules
> are?" Sorry for the confusing wording.
What's wrong with the POSIX shell specification itself?
http://www.opengroup.org/onlinepubs...ilities/sh.html
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| Stephane CHAZELAS 2007-02-18, 1:18 pm |
| 2007-02-16, 12:04(-08), sp_mclaugh@yahoo.com:
> Hi,
>
> If I want to write my own shell, and have it be POSIX-compliant, is
> there a standard regarding what types of syntax I have to support for
> standard IO redirection? For example, the usual/common way to redirect
> input and output of cat might look like:
>
> cat <inFile >outFile
>
> I think every shell supports switching the order of inFile and
> outFile, at least. But what about something like this:
>
> <inFile >outFile cat
> <inFile cat >outFile
>
> I tried the above on Bash, and they work fine. But is it standard? I
> know it's a (very) pedantic question, but I can't seem to find any
> documentation on it.
It is, see
http://www.opengroup.org/onlinepubs....html#tag_02_09
For simple commands, the redirections may be anywhere (but they
are executed from left to right: cmd > a > b is not the same as
cmd > b > a).
For compound commands, they must go after the closing keyword
(done, fi, esac, }) or after the closing ) for subshells.
> Oh, and to make it slightly more interesting, what if you throw pipes
> into the picture? In other words, if the same line includes both
> redirection and (multiple) pipes... is there a "standard" way to
> handle how to behave if:
>
> - the input redirection isn't placed after the first command
> - the output redirection isn't placed at the very end
>
> (either one could be at the beginning, end, or mixed in the middle)
>
> Putting the redirection in the middle would be awful style by the
> user, but... I guess I'd still like to have some shred of predictable
> behavior for such users.
"|" delimit commands, commands include redirections.
cmd with redirections | other cmd with redirections
for ...; done > f | > A cmd > B arg | ( < C cmd...) 2> D
--
Stéphane
|
|
|
|
|