bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: Misbehavior with constants and bash script


From: Alexander Reintzsch
Subject: AW: Misbehavior with constants and bash script
Date: Tue, 20 Nov 2018 11:38:12 +0000

Hello Chet,

thank you for your help and pointing to the posix behavior.

Quoting 
https://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html
"[...]
A non-interactive shell exits with an error status if a variable assignment 
error occurs when no command name follows the assignment statements. A variable 
assignment error occurs, for example, when trying to assign a value to a 
readonly variable.
[...]"

This helps. So what I need to do to force the script to proceed is to add 
another command after the assignment statement.

Before ist was

echo "A"
declare -r vconst="I am fixed."
echo "B"
vconst="new value" # fails here
echo "C" # never reached

and if I add an empty command after the assignment statement it behaves as 
expected.

echo "A"
declare -r vconst="I am fixed."
echo "B"
vconst="new value" : # please note the : at the end. (no operation command)
echo "C" # now printed

End then it does not matter if bash is in posix mode or not.

Thank you for your help in that matter.

Cheers,
Alex


reply via email to

[Prev in Thread] Current Thread [Next in Thread]