declare -r is_debug true
if [ "$is_debug" = true ]; then
printf "%s\n", "is debug"
else
printf "%s\n", "is not debug"
fi
declare -p is_debug
echo "${is_debug-isunset}"
输出:
jian@jian:~/Desktop/pg_src/src4/postgres$ bash /home/jian/scratch/scratchpads/47a6066b9dfaca1c2b13ea2e99f4e929/scratch.sh
is not debug
,declare -r is_debug
isunset
jian@jian:~/Desktop/pg_src/src4/postgres$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
declare -p is_debug
echo "${is_debug-isunset}"
我对输出感到困惑,declare -r is_debug
。我希望它能回来declare -r is_debug
。