Skip to content

Instantly share code, notes, and snippets.

@liliankasem
Created April 7, 2020 14:43
Show Gist options
  • Select an option

  • Save liliankasem/01ff990311ed15de9e13f853d3dda5b8 to your computer and use it in GitHub Desktop.

Select an option

Save liliankasem/01ff990311ed15de9e13f853d3dda5b8 to your computer and use it in GitHub Desktop.
Bash script that uses key-value to assign arguments to variables
#!/bin/bash
# Loop through all the arguments and assign them to a variable
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
case "$KEY" in
WORKING_DIR) working_dir=${VALUE} ;;
SESSION_DB_PATH) session_db_path=${VALUE} ;;
DATA_STORE_TYPE) data_store_type=${VALUE} ;;
AZURE_BLOB_ACCOUNT_NAME) azure_blob_storage_account=${VALUE} ;;
AZURE_BLOB_ACCOUNT_KEY) azure_blob_storage_key=${VALUE} ;;
AZURE_BLOB_ENDPOINT_SUFFIX) azure_blob_endpoint_suffix=${VALUE} ;;
AZURE_BLOB_CONTAINER_NAME) azure_blob_container_name=${VALUE} ;;
*)
esac
done
# Create a config properties file
touch $working_dir/src/main/resources/dev/config.properties
# Write the properties to the config file using argument variables
echo -e $"session.db.path=$session_db_path\n"\
$"data.store.type=$data_store_type\n"\
$"azure.blob.account.name=$azure_blob_storage_account\n"\
$"azure.blob.account.key=$azure_blob_storage_key\n"\
$"azure.blob.endpoint.suffix=$azure_blob_endpoint_suffix\n"\
$"azure.blob.container.name=$azure_blob_container_name"\
> $working_dir/src/main/resources/dev/config.properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment