if [ "$1" == "load-profile" ]; then
  if [ $# -gt 1 ]; then
    if [ "$2" != "--help" ] && [ "$2" != "-h" ]; then
      arguments=("$@")
      profile_arguments=("${arguments[@]:1}")
      profile_arguments=("${profile_arguments[@]/--}")
      profiles=${profile_arguments[@]/%/"/etc/profile"}
      set_output=$(grep -h "^export" $profiles)
      sge_variables=$(export -p | grep "^declare -x SGE")
      env - bash --init-file <(echo "$sge_variables"; echo "$set_output") -i "${@:$(($# + 1))}"
    else
      printf "Usage:\n  $0 $1 /path/to/profile\n"
    fi
  else
    printf "Usage:\n  $0 $1 /path/to/profile\n"
  fi
else
  # whatever
fi

Generated by Ricardo Wurmus using scpaste at Thu Apr 14 14:42:41 2022. CEST. (original)