[ale] what does >&2 mean in bash
Byron Jeff
byronjeff at clayton.edu
Sat May 13 15:49:20 EDT 2017
On Sat, May 13, 2017 at 02:30:15PM -0400, Pete Hardie wrote:
> If memory serves, it means to redirect stderr to the same place a
> stdout. Useful when you want all the output (normal and error) to go
> to the same file/pipe
Sort of. The left hand side is the target while the right hand side is the
source. Technically redirecting stderr to stdout is:
2>&1
2 is stderr and the source. So that redirects stderr to the same place as
stdout. Narahari specified the opposite:
echo ... >&2
Here stdout is the source because it's the default, stderr is the target.
In the end they both accomplish the same goal, which is getting both stdout
and stderr to the same place. The difference is that often stdout is
already redirected whereas typically stderr is generally attached to the
screen. So the goal of the second is to ensure that the echo output goes to
the screen even if stdout overall for the script is redirected to a file,
whereas the first one guarantees that if stdout is already redirected, that
the error messages also follow that redirection.
BAJ
>
> On Sat, May 13, 2017 at 2:11 PM, Narahari 'n' Savitha
> <[1]savithari at gmail.com> wrote:
>
> Friends:
> I see this in a sample code
> echo "[statsgen] restarting myself" >&2
>
> What does the >&2 mean ?
> -N
>
> _______________________________________________
> Ale mailing list
> [2]Ale at ale.org
> [3]http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> [4]http://mail.ale.org/mailman/listinfo
>
> --
> Pete Hardie
> --------
> Better Living Through Bitmaps
>
> References
>
> 1. mailto:savithari at gmail.com
> 2. mailto:Ale at ale.org
> 3. http://mail.ale.org/mailman/listinfo/ale
> 4. http://mail.ale.org/mailman/listinfo
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
--
Byron A. Jeff
Associate Professor: Department of Computer Science and Information Technology
College of Information and Mathematical Sciences
Clayton State University
http://faculty.clayton.edu/bjeff
More information about the Ale
mailing list