[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "cmd | cat > file" does not create 'file' before running 'cmd'
From: |
Paul Jarc |
Subject: |
Re: "cmd | cat > file" does not create 'file' before running 'cmd' |
Date: |
Tue, 24 Sep 2002 11:14:27 -0400 |
User-agent: |
Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i686-pc-linux-gnu) |
Alexis Huxley <ahuxley@gmx.net> wrote:
> However, adding a pipe to the command like this:
>
> rm -f fred
> ls fred | cat > fred
> cat fred
>
> gives an unexpected failure:
>
> ls: fred: No such file or directory
>
> Surely the output file should *still* be created
> before the command runs, and so the 'ls' should
> find it when it is executed, and so there should
> not be an error?
The redirection is bound to the command "cat", not the command
"ls fred | cat". The redirection is done before the command it is
bound to, but all the elements of the pipeline run concurrently.
Sometimes fred might be created before ls looks for it; sometimes not.
You can make sure it's created first like this:
{ ls fred | cat; } > fred
paul