Skip to content

Instantly share code, notes, and snippets.

@JohnMarkT
Created October 11, 2016 14:11
Show Gist options
  • Save JohnMarkT/737c8cb437144959f8a27dd30e54913d to your computer and use it in GitHub Desktop.
Save JohnMarkT/737c8cb437144959f8a27dd30e54913d to your computer and use it in GitHub Desktop.
Shell script to convert environment variables list file to single line to use on the command line
#!/bin/sh
if [ $# -lt 1 ]; then
echo "usage: loadenv filename"
exit 2
fi
HASH="#"
for ENV_FILE in "$@"; do
#echo "file: $ENV_FILE"
if [ -f $ENV_FILE ]; then
#echo "loading: $ENV_FILE"
while read line || [ -n "$line" ]; do
if [[ "$line" == *=* ]] && [[ "$line" != ${HASH}* ]]; then
LOAD_ENV=$LOAD_ENV" "$line
fi
done < "$ENV_FILE"
fi
done
echo $LOAD_ENV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment