diff options
-rwxr-xr-x | bin/envstore | 10 | ||||
-rwxr-xr-x | test/main | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/bin/envstore b/bin/envstore index e3398b6..afc9f3e 100755 --- a/bin/envstore +++ b/bin/envstore @@ -45,7 +45,11 @@ sub load_store { chomp; /^(\S+)\s+(.*)$/ or next; ($key, $value) = ($1, $2); - $store{$key} = $value; + if (exists($store{$key})) { + $store{$key} .= "\n$value"; + } else { + $store{$key} = $value; + } } close($handle); } @@ -55,7 +59,9 @@ sub save_store { umask(0077); open(my $handle, '>', $store_file) or die("Cannot open $store_file: $!"); foreach $key (keys(%store)) { - print $handle "$key\t$store{$key}\n"; + foreach (split(/\n/, $store{$key})) { + print $handle "$key\t$_\n"; + } } close($handle); } @@ -100,6 +100,16 @@ unset hello $envstore clear if ((test_extended)) { + echo "# $envstore save (newline in value)" + export flurbl=$'yo my fresh\nhomies' + $envstore save flurbl + unset flurbl + # XXX eval does not like newlines. Not even in dash. + source <($envstore eval) + [[ $flurbl == $'yo my fresh\nhomies' ]] + unset flurbl + $envstore clear + echo "# invalid invocations" ! $envstore save unset nonexistent |