[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Redirecting error message from ${parameter:?word}
From: |
Michael Siegel |
Subject: |
Re: Redirecting error message from ${parameter:?word} |
Date: |
Tue, 14 Jan 2020 19:01:41 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 |
Am 11.01.20 um 23:33 schrieb Andreas Kusalananda Kähäri:
> On Sat, Jan 11, 2020 at 10:33:13PM +0100, Michael Siegel wrote:
>> Why is it, apparently, not possible to redirect an error message from a
>> ${parameter:?word} expansion to /dev/null within the same shell instance?
>>
>> Here's some code to demonstrate what I mean:
>>
>> $ echo "$BASH_VERSION"
>> 4.4.12(1)-release
>> $ name=Max
>> $ printf 'Hello, %s.\n' "${name:?}"
>> Hello, Max.
>> $ name=
>> $ printf 'Hello, %s.\n' "${name:?}"
>> bash: name: parameter null or not set
>> $ printf 'Hello, %s.\n' "${name:?}" 2>/dev/null
>> bash: name: parameter null or not set
>> $ cat test
>> #!/bin/bash
>>
>> name="$1"
>>
>> printf 'Hello, %s.\n' "${name:?}" 2>/dev/null
>> printf 'Bye\n'
>> $ ./test Max
>> Hello, Max.
>> Bye
>> $ ./test
>> ./test: line 5: name: parameter null or not set
>> $ ./test 2>/dev/null
>> $
>>
>>
>> --Michael
>
> Because it's the shell that produces the diagnostic message, not the
> printf command.
Ok, that's what I thought, but wasn't entirely sure. Thanks for the
clarification.
--Michael