Skip to content

Commit

Permalink
kselftest: allow empty -E option, echo the env var
Browse files Browse the repository at this point in the history
  • Loading branch information
crazoes committed Jun 5, 2024
1 parent 9246e6b commit 09fc67e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions automated/linux/kselftest/kselftest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,18 @@ while getopts "i:n:c:T:t:s:u:p:L:S:b:g:e:E:h" opt; do
export ENVIRONMENT="${OPTARG}"
;;
E)
IFS='=' read -r env_name env_val << EOF
if [ -n "$OPTARG" ]; then
IFS='=' read -r env_name env_val << EOF
$OPTARG
EOF
if [ -z "$env_name" ] || [ -z "$env_val" ]; then
echo "Option -E requires an argument of format ENV_NAME=ENV_VAL"
exit 1
if [ -z "$env_name" ] || [ -z "$env_val" ]; then
echo "Option -E requires an argument of format ENV_NAME=ENV_VAL"
exit 1
fi
# Use eval to set an environment variable dynamically
eval "export ${env_name}=${env_val}"
eval "echo \"${env_name}='\$${env_name}'\""
fi
# Use eval to set an environment variable dynamically
eval "export ${env_name}='${env_val}'"
;;
h|*) usage ;;
esac
Expand Down

0 comments on commit 09fc67e

Please sign in to comment.