| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
set -f is the short form for setting the noglob option.
---In [email protected], <stephane.chazelas@...> wrote :
2016-11-14 12:28:10 -0800, Jim Hill:
> I think Stephane's method is best, though I don't see the need for the
> noglob here, I think
>
> (IFS=\|; set -- $RETVAL; printf %s\\n "$3")
No, the set -o noglob is needed here.
Using a variable unquoted in Bourne-like shells except zsh is
the split+glob operator.
Try with:
RETVAL='*|?|[a-z]'
For instance.
See also
https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells
More generally, when leaving a variable or other expansion
unquoted, you need to consider $IFS and the status of the noglob
option.
> As an alternative if your data doesn't contain newlines, awk is
> specialized for this,
>
> awk -F\| '{print $3}' <<<"$RETVAL"
>
> will do the same job.
Again, that retrieves the 3rd field of every line of $RETVAL, not
the 3rd field in $RETVAL.
If you're going to use that zsh <<< operator (though it's now
also supported by recent versions of ksh93 and bash), you could
as well use ${"${(@s:|:)REVAL}"[3]}.
s:|: splits on |
@ preserves empty elements within quotes
--
Stephane
[Non-text portions of this message have been removed]