Last active
January 20, 2023 08:11
-
-
Save Jimilian/c3a2d8bb6df1b8ca64d02a10d97f510b to your computer and use it in GitHub Desktop.
Returns json created from pipe
This file contains hidden or 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
#!/bin/bash | |
# Example: | |
# > echo "key1 value1 key2 value2" | ./key_value_pipe_to_json.sh | |
# {'key1': value1, 'key2': value2} | |
arr=(); | |
while read x y; | |
do | |
arr=("${arr[@]}" $x $y) | |
done | |
vars=(${arr[@]}) | |
len=${#arr[@]} | |
printf "{" | |
for (( i=0; i<len; i+=2 )) | |
do | |
printf "\"${vars[i]}\": ${vars[i+1]}" | |
if [ $i -lt $((len-2)) ] ; then | |
printf ", " | |
fi | |
done | |
printf "}" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Jimilian, this was really helpful to me! Thanks for writing/publishing it!
I was wondering if you'd be willing to attach a license to it (or if there is one attached that I didn't notice)? I'm hoping to use it in a small bash script for managing AWS credentials. In my draft right now, I reference your Stackoverflow profile as the creator of this piece of code.
Was planning to distribute that under the MIT License, but want to make sure that's alright with you, and if not, I won't!