Re: slpath v0.001
From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 11/11/05
- Next message: RolandRB: "Re: Cutting Filename From Path Via SED?"
- Previous message: Janis Papanagnou: "Re: $@ vs $*"
- In reply to: John Kelly: "Re: slpath v0.001"
- Next in thread: John Kelly: "slpath v0.002"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 11 Nov 2005 08:39:43 +0000
2005-11-10, 14:39(-05), John Kelly:
> On 10 Nov 2005 18:16:01 GMT, Stephane Chazelas
> <stephane_chazelas@yahoo.fr> wrote:
>
>
>>> *//////) _SLPATH=${_SLPATH%//////}; continue ;;
>
>
>>Or simply:
>>
>>*/) _SLPATH=${_SLPATH%"${SLPATH##*[!/]}"};;
>
>
> That's good, Stephane
>
> But since the subexpression always evaluates a string of trailing
> slashes, why do you have quotes enclosing the subexpression?.
For the same reason as for instance in perl, I write
print "foo" instead of print foo, not because there's a risk
that foo may once become a valid function or keyword, but
because print "foo" says my intention.
Without the quotes above, that would mean my intention was to
consider ${SLPATH##...} as a pattern. And that's not true. My
intention was to consider it as a simple string, even if, as you
pointed out, in that very case, that would be the same given
that the pattern would consist only in normal characters.
> Seems like the quotes should enclose the entire RHS of the variable
> assignment.
>
> Strangely though, I tested it without any quotes at all on the RHS,
> and cannot produce a failure even when there are embedded blanks in
> the names.
>
> I've gotten in the habit of quoting the RHS of a variable assignment
> for fear there could be word splitting on the RHS.
>
Your assigning something to a scalar variable, not to an array,
how could word splitting ever occur, there. Word splitting (and
filename generation) can only take place where parameter
expansion can resolve to several words (in list contexts, I
would say), such as in
cmd -- $files
for f in $files
files=($files)
In
(( $var ))
[[ $var ]]
case $var in
foo=$var
They are not necessary, because they are not list contexts.
In
cmd > $files
YMMV.
> But after testing this, I see that RHS quoting is only necessary when
> there is more than one variable (or other text), separated by spaces
> on the RHS. If that is true, then it must also be true that word
> splitting is performed before parameter expansion. I once had a bash
> book with that flowchart in it, but gave it away.
>
> Can anyone verify whether that sequence is correct, or not?
I don't understand that sentence. Word splitting (and filename
generation) is part of the expansion process. A variable may
expand into several words (actually file names) where
applicable, when not quoted.
Note that
foo=$var
doesn't work correctly with some old versions of zsh when the
globsubst option is enabled (i.e. when zsh emulates the other
Bourne like shell bug such as in sh emulation).
foo="$var"
fixes it.
But then, there's a bug in some old versions of bash in:
foo="${var#"$bar"}"
-- Stéphane
- Next message: RolandRB: "Re: Cutting Filename From Path Via SED?"
- Previous message: Janis Papanagnou: "Re: $@ vs $*"
- In reply to: John Kelly: "Re: slpath v0.001"
- Next in thread: John Kelly: "slpath v0.002"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|