diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2010-01-03 13:00:58 +0100 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2010-01-03 13:00:58 +0100 |
commit | ebde27381b403af79ba25cc2d8f3e3823a8ba764 (patch) | |
tree | 02dbcd1cce5b0baaf0b53c524b15bf3c59ba55d0 | |
parent | 5dc79a2cb1afd3bfaafb58ceee93219a29825017 (diff) |
Preserve leading spaces, document shell problems with whitespaces & IFS
-rw-r--r-- | man/1/envstore | 7 | ||||
-rw-r--r-- | src/envstore.c | 6 | ||||
-rwxr-xr-x | test/main | 12 |
3 files changed, 22 insertions, 3 deletions
diff --git a/man/1/envstore b/man/1/envstore index 6ee8f4e..7e65bce 100644 --- a/man/1/envstore +++ b/man/1/envstore @@ -56,6 +56,13 @@ by default, .Sh LIMITATIONS Variable names or values must not contain null bytes or newlines. .Pp +Due to limitations imposed by most shells, it is not possible to save +parameters containing more than one consecutive whitespace. +.Nm +will save and display them correctly, but unless you do +.Ev IFS +trickery, your shell will not be able to load them. +.Pp The current maximum length (in bytes) is 255 bytes for the variable name and 1023 bytes for its content. .Sh AUTHOR diff --git a/src/envstore.c b/src/envstore.c index 43e6d56..3592b29 100644 --- a/src/envstore.c +++ b/src/envstore.c @@ -20,7 +20,7 @@ #define PARAM_LENGTH 256 #define VALUE_LENGTH 1024 -#define SCAN_FORMAT "%255s %1023[^\n]\n" +#define SCAN_FORMAT "%255s%*1[ ]%1023[^\n]\n" static FILE * store_open(char *file) { struct stat finfo; @@ -108,13 +108,13 @@ static void command_disp(char *file, int command) { if (read_items == 0) errx(EXIT_FAILURE, "Unable to read items, store file '%s' corrupt?", file); - else if (read_items == 1) - vcontent[0] = '\0'; if (command == CMD_LIST) printf("%-15s = %s\n", vname, vcontent); else print_escaped(vname, vcontent); + vname[0] = '\0'; + vcontent[0] = '\0'; } if (fclose(fp) != 0) err(EXIT_FAILURE, "fclose %s", file); @@ -73,6 +73,18 @@ eval $(envstore eval) test "$hello" = 'your mom' unset hello +echo "# envstore save (leading space in value)" +envstore save hello ' world' +eval $(envstore eval) +test "$hello" = ' world' +unset hello + +echo "# envstore save (trailing space in value)" +envstore save hello 'world ' +eval $(envstore eval) +test "$hello" = 'world ' +unset hello + echo "# envstore save (overwrite)" envstore save hello world eval $(envstore eval) |