From 04fc5f0847e9c0214dfe30d5858a6eaa70e07147 Mon Sep 17 00:00:00 2001 From: Shereen Reda <85253510+shereenreda1@users.noreply.github.com> Date: Mon, 4 Dec 2023 17:03:50 +0200 Subject: [PATCH] Upload config_parser.sh --- config_parser.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 config_parser.sh diff --git a/config_parser.sh b/config_parser.sh new file mode 100644 index 0000000..0e6b842 --- /dev/null +++ b/config_parser.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +#key here is the first argument and we should trim white spaces + +KEY=$(echo "$1" | tr -d '[:space:]') + + +#value is get from searching the file using the key + +VALUE=$(grep -E "^$KEY=" "config.ini"| cut -d '=' -f 2) + + + +#here we check if the value is empty ,then say it is error, else print the value + +if [ -n "$VALUE" ]; then + echo "$KEY = $VALUE" +else + echo "Error: Key '$KEY' not present in the configuration file." +fi + + +#note : here i put the config.ini in the same directory of config_parser.sh