Created
August 5, 2021 10:39
-
-
Save tundeaoni/e9e9fb3a45f2fb655544cdf2f77d8c76 to your computer and use it in GitHub Desktop.
Sets command args using environment variables with prefix
This file contains 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/sh | |
set -e | |
# Script extract env vairables by prefix | |
# and passes as command arguments | |
cmd=${1} | |
shift | |
if [ "$cmd" = "" ] | |
then | |
echo "Error, set application run command as argument." | |
exit 1 | |
fi | |
args_prefix="APP_" | |
args="" | |
for item in $(env) | |
do | |
key=$(echo $item | cut -d '=' -f1) | |
value=$(echo $item | cut -d '=' -f2) | |
if [[ $key == $args_prefix* ]]; | |
then | |
key=${key#"$args_prefix"} | |
# convert underscores to hyphens | |
# (not consist across all services) | |
# need to this out | |
key=${key//_/-} | |
args="$args--$key $value " | |
fi | |
done | |
args="$args$@" | |
exec $cmd $args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#Test flight