Skip to content

Instantly share code, notes, and snippets.

@malys
Last active August 6, 2019 08:34
Show Gist options
  • Save malys/8dae11d86747dd75ddd4bf1220433a31 to your computer and use it in GitHub Desktop.
Save malys/8dae11d86747dd75ddd4bf1220433a31 to your computer and use it in GitHub Desktop.
[Convert env to args] #args #env #bash
#!/bin/bash
# Convert PREFIX_XXX=YYY variable to --xxx=YYY
PREFIX=$1
DEFAULT=$DEFAULT_ARGS
RESULT=
if [ ${#PREFIX} -ge 2 ]; then
while IFS= read -r line
do
PRE_KEY=$(echo $line | cut -d'=' -f1)
KEY=$(echo $PRE_KEY |sed -e "s/$PREFIX/--/g; s/_/-/g; s/\(.*\)/\L\1/")
VALUE=${line:${#PRE_KEY}}
if [ "$VALUE" == "=@Null" ]; then
RESULT="$KEY $RESULT"
else
RESULT="$KEY$VALUE $RESULT"
fi
done < <(env| grep ^$PREFIX)
echo $RESULT
else
echo $DEFAULT
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment