[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Redirecting error message from ${parameter:?word}
From: |
Michael Siegel |
Subject: |
Redirecting error message from ${parameter:?word} |
Date: |
Sat, 11 Jan 2020 22:33:13 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 |
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
- Redirecting error message from ${parameter:?word},
Michael Siegel <=