bug-bash
[Top][All Lists]
Advanced

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

declare XXX=$(false);echo $?


From: Ulrich Windl
Subject: declare XXX=$(false);echo $?
Date: Fri, 02 Dec 2022 11:28:50 +0100

Surprisingly "declare XXX=$(false);echo $?" outputs "0" (not "1")
There is no indication in the manual page that "declare" ignores the exit code 
of commands being executed to set values.
Actually I's consider it to be a ASH bug, not a documentation bug.

Found in the real code (intended to trigger a bug):
    declare ERRORS=0 ARGS=$(getopt -o "$S_OPTS" -l "$L_OPTS" -n "$0" -- "$@")

    if [ $? -ne 0 ]; then
        usage
    fi

++ getopt -o e:i:v -l exclude:,include:,verbose -n ./buggy.sh -- add -vv 
-iHCTL_DEFS -k SAPDA_DEFS -- -p
./buggy.sh: invalid option -- 'k'
+ declare ERRORS=0 'ARGS= -v -v -i '\''HCTL_DEFS'\'' -- '\''add'\'' 
'\''SAPDA_DEFS'\'' '\''-p'\'''
+ '[' 0 -ne 0 ']'





reply via email to

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