Why does declare not find the environment variable?
From:
Eric Salem
Subject:
Why does declare not find the environment variable?
Date:
Wed, 15 Oct 2025 10:55:04 -0500
User-agent:
Mozilla Thunderbird
Hi all,
I'm trying to understand the behavior of declare when parameter
assignments appear before it:
$ MY_VAR= declare -p MY_VAR
declare -x MY_VAR=""
$ MY_VAR= declare -p | grep MY_VAR
declare -- _="MY_VAR"
$ echo $BASH_VERSION
5.2.37(1)-release
Why does declare find the environment variable in the first case but not
the second? Shouldn't it also exist then?
Thanks,
Eric