Created
January 14, 2020 21:43
-
-
Save melbahja/33fac6f3f823632e880401f5f7451cfb to your computer and use it in GitHub Desktop.
Parse and loop through key value pairs in bash
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
# this is a comment | |
MYVAR=My value | |
OKOK=asas | |
YES=asja |
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
#!/usr/bin/bash | |
# Copyright 2020 - MIT, Mohamed Elbahja (http://git.io/mohamed). | |
cat file.conf | while read line || [[ -n $line ]]; | |
do | |
[[ ${line//[[:space:]]/} =~ ^#.* || -z "$line" ]] && continue | |
echo $line | tr "=" "\n" | while read -r key; do | |
read -r value | |
echo "key: ${key} and value: ${value}"; | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment