Defining a variable with or without export

后端 未结 14 1462
借酒劲吻你
借酒劲吻你 2020-11-22 09:58

What is export for?

What is the difference between:

export name=value

and

name=value
14条回答
  •  有刺的猬
    2020-11-22 10:34

    Here's yet another example:

    VARTEST="value of VARTEST" 
    #export VARTEST="value of VARTEST" 
    sudo env | grep -i vartest 
    sudo echo ${SUDO_USER} ${SUDO_UID}:${SUDO_GID} "${VARTEST}" 
    sudo bash -c 'echo ${SUDO_USER} ${SUDO_UID}:${SUDO_GID} "${VARTEST}"'  
    

    Only by using export VARTEST the value of VARTEST is available in sudo bash -c '...'!

    For further examples see:

    • http://mywiki.wooledge.org/SubShell

    • bash-hackers.org/wiki/doku.php/scripting/processtree

提交回复
热议问题