How can I split the following String
into key-value
pairs using bash
?
SOURCE="'key1=val 1' 'key2=val 2'"
My output goal is:
key1=val 1
key2=val 2
- I can only input a single String as a variable
- I cannot pass the variable as array
- I want to output only the key-value pair plain as is
- I want to honor the quotes, as I don't know how to separate the key-value pairs else
- My keys never contain spaces, but values will
'key1=I'm ok'
?'key1=I\'m ok'
? I'm asking because a single-quoted string can not contain single quotes in the shell, which may have an impact on ways to write solutions.