help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redirection and subshells and file position pointer


From: Greg Wooledge
Subject: Re: Redirection and subshells and file position pointer
Date: Wed, 9 Jul 2025 15:43:53 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

> On Wed, Jul 9, 2025, 3:21 PM Stan Marsh <gazelle@xmission.com> wrote:
> > Anyway, in the line containing the "file" command, the intent is to have
> > the output of
> > "file" show up in the log and also be used as the string to be compared to
> > see if the
> > file is a text file.  So, I figured that piping it to "tee /dev/stderr"
> > would do what
> > I want.

Unfortuantely, the semantics of /dev/stderr and its cousins are
OS-dependent.  You'll get different behavior between Linux and BSD,
and of course many commercial Unix systems don't have it at all.

If I understand the request correctly, you wanted to do this:

    result=$(file "$somefile" | tee /dev/stderr)

You're forking an entire new process just to copy the output of one
command to stderr.  You'd be better off doing it this way:

    result=$(file "$somefile")
    printf 'file result: "%s"\n' "$result" >&2

Not only is this consistent across all operating systems, but it's
also faster.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]