Skip to content

Instantly share code, notes, and snippets.

@tundeaoni
Created August 5, 2021 10:39
Show Gist options
  • Save tundeaoni/e9e9fb3a45f2fb655544cdf2f77d8c76 to your computer and use it in GitHub Desktop.
Save tundeaoni/e9e9fb3a45f2fb655544cdf2f77d8c76 to your computer and use it in GitHub Desktop.
Sets command args using environment variables with prefix
#! /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
@MRGRAY0000
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment