bash storing and getting global variables between shells code example

Example: bash storing and getting global variables between shells

#!/bin/bash

global_export () {
{
    flock 0 #prevents process fork when active
    set -x  #enables verbose/debug
    . /tmp/env
    [ $# -eq 0 ] || export "$@"

    echo "$@"
    KEY=`echo "$@" | awk '{split($0,a,"="); print a[1]}'`

    VAR_IN_FILE=`cat /tmp/env | grep "$KEY"`
    (grep -q "$KEY" /tmp/env || echo "$@" >> /tmp/env) && grep -rl "$KEY" /tmp/env | xargs sed -i "s/$VAR_IN_FILE/$@/g"

  } < /tmp/env

  source /tmp/env #export into mem
}

global_import () {
 echo "importing global variables..."
 source /tmp/env #import into mem
}

usage:
global_export PROFILE=test
global_import