* ash -c 'echo ${#1#}' name:'1=#'
*/
static NOINLINE ssize_t
-varvalue(char *name, int varflags, int flags, struct strlist *var_str_list)
+varvalue(char *name, int varflags, int flags, struct strlist *var_str_list, int *nulonly)
{
const char *p;
int num;
int quotes = (discard ? 0 : (flags & QUOTES_ESC)) | QUOTES_KEEPNUL;
int syntax = quoted ? DQSYNTAX : BASESYNTAX;
- sep = quoted ? ((flags & EXP_FULL) << CHAR_BIT) : 0;
+ sep = *nulonly ? (flags & EXP_FULL) << CHAR_BIT : 0;
+ *nulonly = 0;
switch (*name) {
case '$':
}
/* fall through */
case '*':
- sep = ifsset() ? (unsigned char)(ifsval()[0]) : ' ';
+ sep |= ifsset() ? (unsigned char)(ifsval()[0]) : ' ';
param:
ap = shellparam.p;
sepc = sep;
+ *nulonly = !sepc;
if (!ap)
return -1;
while ((p = *ap++) != NULL) {
char subtype;
int quoted;
char easy;
+ int nulonly;
char *var;
int patloc;
int startloc;
quoted = flags & EXP_QUOTED;
var = p;
easy = (!quoted || (*var == '@' && shellparam.nparam));
+ nulonly = easy;
startloc = expdest - (char *)stackblock();
p = strchr(p, '=') + 1; //TODO: use var_end(p)?
again:
- varlen = varvalue(var, varflags, flags, var_str_list);
+ varlen = varvalue(var, varflags, flags, var_str_list, &nulonly);
if (varflags & VSNUL)
varlen--;
/* Remove any recorded regions beyond start of variable */
removerecordregions(startloc);
record:
- recordregion(startloc, expdest - (char *)stackblock(), quoted);
+ recordregion(startloc, expdest - (char *)stackblock(), nulonly);
}
end:
--- /dev/null
+set -- abc "d e"
+
+echo 'Testing: !IFS $*'
+unset IFS; for a in $*; do echo ".$a."; done
+echo 'Testing: !IFS $@'
+unset IFS; for a in $@; do echo ".$a."; done
+echo 'Testing: !IFS "$*"'
+unset IFS; for a in "$*"; do echo ".$a."; done
+echo 'Testing: !IFS "$@"'
+unset IFS; for a in "$@"; do echo ".$a."; done
+
+echo 'Testing: IFS="" $*'
+IFS=""; for a in $*; do echo ".$a."; done
+echo 'Testing: IFS="" $@'
+IFS=""; for a in $@; do echo ".$a."; done
+echo 'Testing: IFS="" "$*"'
+IFS=""; for a in "$*"; do echo ".$a."; done
+echo 'Testing: IFS="" "$@"'
+IFS=""; for a in "$@"; do echo ".$a."; done
+
+echo Finished
--- /dev/null
+set -- abc "d e"
+
+echo 'Testing: !IFS $*'
+unset IFS; for a in $*; do echo ".$a."; done
+echo 'Testing: !IFS $@'
+unset IFS; for a in $@; do echo ".$a."; done
+echo 'Testing: !IFS "$*"'
+unset IFS; for a in "$*"; do echo ".$a."; done
+echo 'Testing: !IFS "$@"'
+unset IFS; for a in "$@"; do echo ".$a."; done
+
+echo 'Testing: IFS="" $*'
+IFS=""; for a in $*; do echo ".$a."; done
+echo 'Testing: IFS="" $@'
+IFS=""; for a in $@; do echo ".$a."; done
+echo 'Testing: IFS="" "$*"'
+IFS=""; for a in "$*"; do echo ".$a."; done
+echo 'Testing: IFS="" "$@"'
+IFS=""; for a in "$@"; do echo ".$a."; done
+
+echo Finished