zsh-workers
 help / color / mirror / code / Atom feed
* Re: sh vs zsh behavior
       [not found] <316A7A6F.41C6@uoknor.edu>
@ 1996-04-09 15:01 ` Timothy J. Luoma
  1996-04-09 16:55   ` Zoltan Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Timothy J. Luoma @ 1996-04-09 15:01 UTC (permalink / raw)
  To: Clinton Bunch; +Cc: ZSH Users List

On Tue, 9 Apr 1996, Clinton Bunch wrote:

> Timothy J. Luoma wrote:
> >
> > #!/usr/local/bin/zsh -f
> >
> > test="one two three"
> >
> > for i in $test

> try replacing the above line with this:
>   for i in $(echo $test)

> > ps -- I'm using 2.6-beta13 under NeXTStep/m68k
>
> That worked for me under 2.6-beta13 on AIX
>
> 	Hope this helps,
> 	Clinton

YES!

That did it.

In a grand total of 16 minutes since my message hit the list, a reply was
in my hand....

Thanks!

TjL

ps -- if anyone know how to mimic the csh-multiple comparison, I'd still
like to hear about it.



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

* Re: sh vs zsh behavior
  1996-04-09 15:01 ` sh vs zsh behavior Timothy J. Luoma
@ 1996-04-09 16:55   ` Zoltan Hidvegi
  1996-04-09 17:04     ` Timothy J. Luoma
  0 siblings, 1 reply; 4+ messages in thread
From: Zoltan Hidvegi @ 1996-04-09 16:55 UTC (permalink / raw)
  To: luomat; +Cc: zsh-workers

> On Tue, 9 Apr 1996, Clinton Bunch wrote:
> 
> > Timothy J. Luoma wrote:
> > >
> > > #!/usr/local/bin/zsh -f
> > >
> > > test="one two three"
> > >
> > > for i in $test
> 
> > try replacing the above line with this:
> >   for i in $(echo $test)

No, do not try this.  It works, but it is unnecessarily complicated and zsh
forks just to split $test.  Instead you should read the FAQ and the manual.

You can use setopt shwordsplit to get sh compatible word splitting (see man
zshoptions).  You can also call sh as sh, or you can use $=test (as
described in man zshexpn).

To test if a word is in {one, two, three, four} you can use:

if [[ somethin == (one|two|three) ]] then
	...
else
	...
fi

For more details, see man zshexpn, section FILENAME GENERATION (GLOBBING).

Use all of the above with 2.6-beta13 (2.5.03 is far more buggy than recent
betas I think).

Bye,

Zoltan



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

* Re: sh vs zsh behavior
  1996-04-09 16:55   ` Zoltan Hidvegi
@ 1996-04-09 17:04     ` Timothy J. Luoma
  0 siblings, 0 replies; 4+ messages in thread
From: Timothy J. Luoma @ 1996-04-09 17:04 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: zsh-workers


The best suggestion I think I have in this situation is to use case/esac

case $test in
   one|two|three)
	echo match
   ;;

   *)
	echo no match
   ;;
esac


I don't know why I didn't just think of that in the first place.

It requires no special syntax or setopts, and allows for easy
expansion/removal of matches.

TjL

--
Timothy J. Luoma 	<luomat@capitalist.princeton.edu>
USENET: Please CC this address on replies to my posts, things vanish fast.
NeXT Info available via email! 	Send message with SUBJECT 'send info'
>>>> Please: No NeXTMail, use MIME for attachments <<<<





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

* sh vs zsh behavior
@ 1996-04-09 14:38 Timothy J. Luoma
  0 siblings, 0 replies; 4+ messages in thread
From: Timothy J. Luoma @ 1996-04-09 14:38 UTC (permalink / raw)
  To: ZSH Users List


Compare these two simple scripts (one in sh, one in zsh)

########################################################################
#!/bin/sh

test="one two three"

for i in $test
do
	echo this is $i
	echo loop
done

exit 0

########################################################################
#!/usr/local/bin/zsh -f

test="one two three"

for i in $test
do
	echo this is $i
	echo loop
done

exit 0
########################################################################
########################################################################

THE /bin/sh SCRIPT PRODUCES THE OUTPUT:
this is one
loop
this is two
loop
this is three
loop

THE zsh SCRIPT PRODUCES THE OUTPUT:
this is one two three
loop



I want to have 'zsh' behave like 'sh' in this matter.  Is there a way to
do this?

What I am specifically trying to do is check to see if some variable is
equal to any type part of a list of possibilities.

I can do this easily in CSH (*shudder*) via:

if ( "$variable" == "one" || "$variable" == "two" || "$variable" == "three
) then
# that should all be one line above

	echo "Match"

else

	echo "No Match"

endif


How can I do multiple comparisons in ZSH?

Thanks

TjL

ps -- I'm using 2.6-beta13 under NeXTStep/m68k





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

end of thread, other threads:[~1996-04-09 17:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <316A7A6F.41C6@uoknor.edu>
1996-04-09 15:01 ` sh vs zsh behavior Timothy J. Luoma
1996-04-09 16:55   ` Zoltan Hidvegi
1996-04-09 17:04     ` Timothy J. Luoma
1996-04-09 14:38 Timothy J. Luoma

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).