[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Redirecting error message from ${parameter:?word}
From: |
Eli Schwartz |
Subject: |
Re: Redirecting error message from ${parameter:?word} |
Date: |
Sun, 12 Jan 2020 01:37:06 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 |
On 1/11/20 5:33 PM, Andreas Kusalananda Kähäri wrote:
> Because it's the shell that produces the diagnostic message, not the
> printf command. Redirecting the printf command's error stream will not
> do anything.
>
> To redirect the diagnostic message, you would have te redirect the
> shell's error stream. You can do that by, for example, placing the
> printf in a subshell and redirecting that subshell's error stream:
>
> $ ( printf 'Hello, %s.\n' "${name:?}" ) 2>/dev/null
> $
>
> This is also equivalent to what happens in your second example where you
> redirect the script's error stream.
It should suffice to use any compound command; the simplest would be to
use { cmd; } 2>/dev/null
No subshell needed, which it seems is something the OP cared about.
--
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User
signature.asc
Description: OpenPGP digital signature