Last active
August 6, 2019 08:34
-
-
Save malys/8dae11d86747dd75ddd4bf1220433a31 to your computer and use it in GitHub Desktop.
[Convert env to args] #args #env #bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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