bug-bash
[Top][All Lists]
Advanced

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

declare -g -x in function does not get exported in this script - not on


From: vbox
Subject: declare -g -x in function does not get exported in this script - not on ubunto 20.04 and centos 8
Date: Wed, 2 Jun 2021 15:54:34 -0600 (MDT)

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=. 
-fstack-protector-strong -Wformat -Werror=format-security -Wall 
-Wno-parentheses -Wno-format-security
uname output: Linux ubandroid 5.8.0-53-generic #60~20.04.1-Ubuntu SMP Thu May 6 
09:52:46 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Machine: aarch64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-i8mNiV/bash-5.0=. 
-fstack-protector-strong -Wformat -Werror=format-security -Wall 
-Wno-parentheses -Wno-format-security
uname output: Linux it4us.top 5.4.0-1035-raspi #38-Ubuntu SMP PREEMPT Tue Apr 
20 21:37:03 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
Machine Type: aarch64-unknown-linux-gnu



Bash Version: 5.0
Patch Level: 17
Release Status: release

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib  -D_GNU_SOURCE -DRECYCLES_PIDS 
-DDEFAULT_PATH_VALUE='/usr/local/bin:/usr/bin'  -DSYSLOG_HISTORY -O2 -g -pipe 
-Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS 
-fexceptions -fstack-protector-strong -grecord-gcc-switches 
-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 
-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic 
-fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection 
-Wno-parentheses -Wno-format-security
uname output: Linux localhost.localdomain 4.18.0-240.22.1.el8_3.x86_64 #1 SMP 
Thu Apr 8 19:01:30 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

Bash Version: 4.4
Patch Level: 19
Release Status: release

Description:
--------------------------first script where declare -x -g works
#!/usr/bin/bash 

xas(){
        [[ $cnt == 1 ]] && declare -g -x ThreeNestedbug="not a 3-nested 
variable-bug !!"
        [[ $cnt == 2 ]] && ThreeNestedbug=""
}

bar(){

        [[ $cnt == 1 ]] && declare -g -x nestedbug="not a nested variable-bug 
!!"
        [[ $cnt == 2 ]] && nestedbug=""
        xas
}

foo(){

        [[ $cnt == 0 ]] && declare -g -x bug="not a variable-bug !!" 
        [[ $cnt == 1 ]] && bar && echo ${nestedbug:?"variable should be  shown"}
        [[ $cnt == 2 ]] && bar && echo ${nestedbug} " nestedbug variable should 
be not shown"
        [[ $cnt == 3 ]] && bug=""
}

cnt=0
foo
echo ${bug:?"variable should be shown"} 
cnt=$(( $cnt  + 1))
foo
echo ${ThreeNestedbug:?"variable should be shown"} 
echo ${nestedbug:?"variable not shown"} 
cnt=$(( $cnt  + 1))
foo
echo ${ThreeNestedbug} "ThreeNestedbug variable should not be shown"
echo ${nestedbug} "variable not shown"
cnt=$(( $cnt  + 1))
foo
echo ${bug:?"yes - variable should not be shown"}
---------------------end of working script 
------------------------------------------------
--------------------------begin of not working script 
------------------------------------
#!/usr/bin/bash
doTrap(){
        cd ${OPWD}
        exit $1
}

doExit(){
        bannerPrint $1
        kill -15  $$
}

bannerPrint(){
        printf "\n\n$*\n\n"
}

mkMasterKey(){
        :
}

mkSubmissionMsg(){
        submissionMsg="\n\
e-mail certificate request file ${PWD}/certreqs/${1}.${sExt}.csr.pem to $_WWW 
service provider at $_EMAIL .\n\
If you did not receive and answer within a short time, your certificate might 
have been rejected\n\
because of incorrect data, such as mismatched e-mail address, implausible 
country or postal code.\n\
$_WWW needs to be able to contact certificate holder for security and business 
reasons.\n\
Only the ${1} 'id' will be stored in the signed certificate.\n\
The remaining data stays in your certificate signig request (csr).\n\
It will be needed to sign additional future communication.\n\
Keep backed up!"
echo ${submissionMsg}
}

mkPersonalCsr(){
umask 0077
sExt=p
bannerPrint Generating CSR for ${2}
PS3="Enter corresponding number of chosen key - control-d (^D) to request a new 
one: "
select key in $( ls -1 ${SAFE_STORE}/private/*.key.pem ); do break; done
#read -s -p "enter password for newly created key $key: " passw1 && export 
passw1 
if [[ "#${key}#" = "##"  || ${key} = "0" ]]
then 
        key=$PWD/private/$2.${sExt}.key.pem
        _key=$(basename $key)
        openssl req -new -subject -newhdr ${passw1:+-passout env:passw1} 
-verbose -subj "${1}/UID=skey:${_key}" -keyout ${key} -out 
${SAFE_STORE}/certreqs/${2}.${sExt}.csr.pem || \
                doExit "Exiting from line number ${LINENO}" $?
else 
        _key=$(basename $key)
        openssl req -new -subject -newhdr -verbose -subj 
"${1}/UID=skey:${_key}" -key ${key} ${passw1:+-passout env:passw1} -out 
${SAFE_STORE}/certreqs/${2}.${sExt}.csr.pem || \
                doExit "Exiting from line number ${LINENO}" $?
fi
bannerPrint $( mkSubmissionMsg $2 ${_key} )
}

mkDeviceCsr(){
umask 0077
sExt=d
bannerPrint Generating CSR for ${2}
PS3="Enter corresponding number of chosen key - control-d (^D) to request a new 
one: "
select key in $( ls -1 ${SAFE_STORE}/private/*.key.pem ); do break; done
if [[ "#${key}#" = "##"  || ${key} = "0" ]]
then 
        read -s -e -p "enter password for newly created key $key: " passw1 && 
export passw1 
        openssl req -new -subject -newhdr -verbose -passout env:passw1 -subj 
"${1}/UID=skey:${2}.${sExt}" -keyout $PWD/private/${2}.${sExt}.key.pem -out 
${SAFE_STORE}/certreqs/${2}.${sExt}.csr.pem || \
                doExit "Exiting from line number ${LINENO}" $?
fi 
if [ "#${key}#" != "##" ]
then
        read -s -e -p "enter password for existing key $key: " passw1 && export 
passw1
        openssl req -new -subject -newhdr -verbose -passout env:passw1 -subj 
"${1}/UID=skey:${2}.${sExt}" -keyin ${SAFE_STORE}/private/${key} -out 
${SAFE_STORE}/certreqs/${2}.${sExt}.csr.pem || \
                doExit "Exiting from line number ${LINENO}" $?
fi
bannerPrint $( mkSubmissionMsg $2 ${key} )
}

mkServerCsr(){
umask 0077
sExt=s
bannerPrint Generating CSR for ${2}
PS3="Enter corresponding number of chosen key - control-d (^D) to request a new 
one: "
select key in $( ls -1 ${SAFE_STORE}/private/*.key.pem ); do break; done
if [[ "#${key}#" = "##"  || ${key} = "0" ]]
then 
        read -s -e -p "enter password for newly created key $key: " passw1 && 
export passw1 
        openssl req -new -subject -newhdr -verbose -passout env:passw1 -subj 
"${1}/UID=skey:${2}.${sExt}" -keyout $PWD/private/${2}.${sExt}.key.pem -out 
${SAFE_STORE}/certreqs/${2}.${sExt}.csr.pem || \
                doExit "Exiting from line number ${LINENO}" $?
fi 
if [ "#${key}#" != "##" ]
then
        read -s -e -p "enter password for existing key $key: " passw1 && export 
passw1
        openssl req -new -subject -newhdr -verbose -passout env:passw1 -subj 
"${1}/UID=skey:${2}.${sExt}" -keyin ${SAFE_STORE}/private/${key} -out 
${SAFE_STORE}/certreqs/${2}.${sExt}.csr.pem || \
                doExit "Exiting from line number ${LINENO}" $?
fi
bannerPrint $( mkSubmissionMsg $2 ${key})
}

makeCsrSubjectString(){
uCN=${1^^}
shift
uUIDORG=${1^^}
shift
uFN=${1^^}
shift
uMN=${1^^}
shift
uLN=${1^^}
shift
uA=${1^^}
shift
uL=${1^^}
shift
uST=${1^^}
shift
uC=${1^^}
uC=${uC:?"country is required"}
shift
uZIP=${1^^}
uZIP=${uZIP:?"postalCode is required"}
shift
lEMAIL=${1,,}
lEMAIL=${lEMAIL:?"email is required"}
shift
uFDQN=${1^^}
lFDQN=${1,,}
IFS=. read -a uaFDQN <<< ${uFDQN}
IFS=. read -a laFDQN <<< ${lFDQN}
uORG=${uaFDQN[-1]}
lORG=${laFDQN[-1]}
uDQN=${uFDQN%.${uORG}}
dashWWW=${1//./-}
udashWWW=${dashWWW^^}
ldashWWW=${dashWWW,,}
uO=${uDQN}
O=${uFDQN}
shift
www="${lFDQN}"
sub="\
/CN=${uCN}\
/UID=${uFN:+firstName:$uFN}\
/UID=${uMN:+middleName:$uMN}\
/UID=${uLN:+lastName:$uLN}\
/UID=${uUIDORG:+organization:$uUIDORG}\
/UID=${uA:+streetAddress:$uA}\
/L=${uL}/ST=${uST}\
/C=${uC}\
/UID=${uZIP:+postalCode:$uZIP}\
/DC=${uO}\
/DC=${uORG}\
/emailAddress=${lEMAIL}"
}

doOptions(){
        declare -g -x nestedbug="NOT BUG"
        return 0 
        while getopts "dk:psu:x" opts $@
        do
                OPTIND=1
                case ${opts} in
                        d) echo Device;;
                        k) shift;keyIn=$1;;
                        p) echo Personal;;
                        s) echo Server;;
                        u) shift;declare -g -x tmpuuid=$1;;
                        x) set -x 2> /dev/null ;;
#                       *) doExit $helpMsg 1;;
                esac
                shift
        done
}

doRun(){
#run=$( doOptions -p -u sdfgsdfgsdf -d -s -x )
run=$( doOptions $* )
echo ${nestedbug:?error}
[[ "#${tmpuuid}#" == "##" ]] && typeset -p && exit 0
[[ "#${tmpuuid}#" == "##" ]] && tmpuuid=$( uuidgen -r )
PS3="Select certificate type: " 
[ "#${run}#" = "##" ] && select run in Device Personal Server; do break; done
_WWW=VBOX.ORG #set to ca-organization sigining this certificate 
_EMAIL=webmaster@it4us.top
SAFE_STORE="$HOME/.${_WWW}.store" #to your secret but separate safe storage 
area 
[ -d  ${SAFE_STORE}/private ] || mkdir -p 
${SAFE_STORE}/{certreqs,certs,crl,newcerts,private} 
cd ${SAFE_STORE} || doExit "Failed to create ${SAFE_STORE} directory." 
${LINENO} 1
shift
if [ $# -lt 10 ] 
then 
        read -p 'Enter your Organization: '  ORGN  || doExit "Exiting from line 
number ${LINENO}" $?
        read -p 'Enter your first name: '  FIRSTN  || doExit "Exiting from line 
number ${LINENO}" $?
        read -p 'Enter your middle name: '  MIDDLEN  || doExit "Exiting from 
line number ${LINENO}" $?
        read -p 'Enter your last name: '  LASTN  || doExit "Exiting from line 
number ${LINENO}" $?
        read -p 'Enter your Address: ' A || doExit "Exiting from line number 
${LINENO}" $? 
        read -p 'Enter City/Locality: ' L || doExit "Exiting from line number 
${LINENO}" $? 
        read -p 'Enter State/Province: ' ST  || doExit "Exiting from line 
number ${LINENO}" $?
        while [ "#${C}#" = "##" ]
        do
                read -p 'Enter your two lettered Country abbreviation 
[Required]: ' C  || doExit "Exiting from line number ${LINENO}" $?
        done
        while [ "#${ZIP}#" = "##" ]
        do
                read -p 'Enter Postal Code [Required]: ' ZIP  || doExit 
"Exiting from line number ${LINENO}" $?
        done
        while [ "#${EMAIL}#" = "##" ]
        do
                read -p 'Enter the complete e-mail for this identity ( e.g 
first.last@emailaddress.org) [Required]: '  EMAIL  || doExit "Exiting from line 
number ${LINENO}" $?
        done
        makeCsrSubjectString "${tmpuuid}" "$ORGN" "$FIRSTN" "$MIDDLEN" "$LASTN" 
"$A" "$L" "$ST" "$C" "$ZIP" "$EMAIL" "$_WWW" && "mk${run}Csr" "${sub}" 
"${tmpuuid}"
else
        makeCsrSubjectString "${tmpuuid}" "$1" "$2" "$3" "$4" "$5" "$6" "$7" 
"$8" "$9" "${10}" "$_WWW" && "mk${run}Csr" "${sub}" "${tmpuuid}"
fi
}

testIt(){
#doRun -p "" "" "" "" "" "" "" us postalcode email #<< this would generate a 
csr with the minimally required data
doRun "" "" "" "" "" "" "" us postalcode email #<< this should result in 
interactive data collection 
#doRun -p "" "" "" "" "" "" "" country postalcode email #<< this should result 
in error 
#doRun -p "" "" "" "" "" "" "" "" postalcode email #<< this should result in 
error 
#doRun -p "" "" "" "" "" "" "" country "" email #<< this should result in error 
#doRun -p "" "" "" "" "" "" "" country postalcode "" #<< this should result in 
error 
}

#main program below
OPWD=$PWD
helpMsg="  $0 \n
        create certificate request for \n
        -d device \n
        -p person \n
        -s server \n
"
trap doTrap  SIGHUP SIGINT SIGQUIT SIGPIPE SIGTERM
#doRun -p "Your Org" First Middle Last "street address" city state/province 
country postalcode email 
#doRun -p "Super Computer Solutions, Inc." Charles 'K.' Wonder "100 Main Street 
#100A" cheyenne wy us 82001 charles-wonder@secretmail.io 
#testIt
doRun "-p $@"
cd ${OPWD}
--------------------end of not working script 
-------------------------------------------
        [Detailed description of the problem, suggestion, or complaint.]
----------------------------------------------begin excerpt of execution log of 
no working script -----------------------
doOptions(){
        declare -g -x nestedbug="NOT BUG"
        return 0 
        while getopts "dk:psu:x" opts $@
        do
                OPTIND=1
                case ${opts} in
                        d) echo Device;;
                        k) shift;keyIn=$1;;
                        p) echo Personal;;
                        s) echo Server;;
                        u) shift;declare -g -x tmpuuid=$1;;
                        x) set -x 2> /dev/null ;;
#                       *) doExit $helpMsg 1;;
                esac
                shift
        done
}

doRun(){
#run=$( doOptions -p -u sdfgsdfgsdf -d -s -x )
run=$( doOptions $* )
echo ${nestedbug:?error}
[[ "#${tmpuuid}#" == "##" ]] && typeset -p && exit 0
#main program below
OPWD=$PWD
+ OPWD=/home/vbox/gits/vbox-docs
helpMsg="  $0 \n
        create certificate request for \n
        -d device \n
        -p person \n
        -s server \n
"
+ helpMsg='  make-bug-csr.sh \n
        create certificate request for \n
        -d device \n
        -p person \n
        -s server \n
'
trap doTrap  SIGHUP SIGINT SIGQUIT SIGPIPE SIGTERM
+ trap doTrap SIGHUP SIGINT SIGQUIT SIGPIPE SIGTERM
#doRun -p "Your Org" First Middle Last "street address" city state/province 
country postalcode email 
#doRun -p "Super Computer Solutions, Inc." Charles 'K.' Wonder "100 Main Street 
#100A" cheyenne wy us 82001 charles-wonder@secretmail.io 
#testIt
doRun "-p $@"
+ doRun '-p -u' trwretwer
++ doOptions -p -u trwretwer
++ declare -g -x 'nestedbug=NOT BUG'
++ return 0
+ run=
make-bug-csr.sh: line 173: nestedbug: error
------------------------------------------------------end bug.log 
-------------------------------------------------
Repeat-By:
        [Describe the sequence of events that causes the problem
        to occur.]
        bash.bug.sh
        bash -x -v  make-bug-csr.sh  -u trwretwer > bug.log 2>&1 



reply via email to

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