zsh-users
 help / color / mirror / code / Atom feed
* Parameter Expansion questions
@ 1998-08-17 13:57 David R. Favor
  1998-08-17 14:45 ` Zefram
  0 siblings, 1 reply; 4+ messages in thread
From: David R. Favor @ 1998-08-17 13:57 UTC (permalink / raw)
  To: Zsh List

In ksh, word splitting occurs auto-magically via setting IFS, thus:

   SAVEIFS="$IFS"
   IFS=:
   splitpath=$PATH
   IFS="$SAVEIFS

results in $splitpath having $PATH contents with ':' characters changed
to blanks.

In zsh, I'm having a challenge deciphering the manual about parameter
expansion options. I've tried the following, without success. All fragments
set $IFS=: before expansion:

   export SH_WORD_SPLIT     // explicit 'set SH_WORD_SPLIT'
   splitpath=$*

and

   splitpath=${=PATH}       // implicit 'set SH_WORD_SPLIT'

and

   splitpath=${buf:s:':':}  // word split s:char:

Can someone let me know what I'm doing wrong in each of these situations?

I did figure out that this works:

   splitpath=${buf:gs/:/ /}

Also,

Also, a pointer to some good examples of parameter expansion would be great.

Thanks.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Parameter Expansion questions
  1998-08-17 13:57 Parameter Expansion questions David R. Favor
@ 1998-08-17 14:45 ` Zefram
  1998-08-17 15:10   ` Bruce Stephens
  1998-08-17 17:09   ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Zefram @ 1998-08-17 14:45 UTC (permalink / raw)
  To: David R. Favor; +Cc: zsh-users

David R. Favor wrote:
>In zsh, I'm having a challenge deciphering the manual about parameter
>expansion options. I've tried the following, without success. All fragments
>set $IFS=: before expansion:
>
>   export SH_WORD_SPLIT     // explicit 'set SH_WORD_SPLIT'
>   splitpath=$*

zsh doesn't perform field splitting on the RHS of scalar variable
assignments.  Try "echo $*" under equivalent circumstances.

>I did figure out that this works:
>
>   splitpath=${buf:gs/:/ /}

That's doing a substitution, rather than field splitting.  Since the
effect you're asking for is actually a substitution, rather than field
splitting (since you're just joining up the fields again anyway), this
is logically the correct thing to do.

OTOH, I suspect that you *really* want to be using an array parameter.
$path is an array version of $PATH, so you don't even need to do the
splitting manually in that case.

-zefram


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Parameter Expansion questions
  1998-08-17 14:45 ` Zefram
@ 1998-08-17 15:10   ` Bruce Stephens
  1998-08-17 17:09   ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Bruce Stephens @ 1998-08-17 15:10 UTC (permalink / raw)
  To: zsh-users; +Cc: David R. Favor

"Zefram" <zefram@tao.co.uk> writes:

> OTOH, I suspect that you *really* want to be using an array
> parameter.  $path is an array version of $PATH, so you don't even
> need to do the splitting manually in that case.

Yes, when I first read it, I came up with

	splitpath="$path"

But that's surely not a particularly useful thing to do.  Well, I
can't think of a use, anyway.  Maybe I'm just not being creative
today.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Parameter Expansion questions
  1998-08-17 14:45 ` Zefram
  1998-08-17 15:10   ` Bruce Stephens
@ 1998-08-17 17:09   ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 1998-08-17 17:09 UTC (permalink / raw)
  To: Zefram, zsh-users

On Aug 17,  3:45pm, Zefram wrote:
} Subject: Re: Parameter Expansion questions
}
} zsh doesn't perform field splitting on the RHS of scalar variable
} assignments.

It does when shwordsplit is set, but not with ${=param}.  That seems a
bit counterintuitive.  Of course, you don't really notice unless IFS has
been changed, but ...

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-08-17 17:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-08-17 13:57 Parameter Expansion questions David R. Favor
1998-08-17 14:45 ` Zefram
1998-08-17 15:10   ` Bruce Stephens
1998-08-17 17:09   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).