zsh-users
 help / color / mirror / code / Atom feed
* variable expanding to `*` matches a literal `*` in case cond. construct
@ 2019-12-15  8:41 Oğuz
  2019-12-15 10:05 ` Andreas Kusalananda Kähäri
  0 siblings, 1 reply; 12+ messages in thread
From: Oğuz @ 2019-12-15  8:41 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 518 bytes --]

Although one would expect it to print "match"

    zsh -c 'case foo in $1) echo match; esac' sh '*'

above command doesn't print anything; if `*` is a result of a variable
expansion,
it matches only a literal asterisk. All the other shells I could find
(including ksh
from 2010) does print "match". I know this is a compliancy issue and zsh
doesn't
claim to be compatible with any other shell, I really wonder; was this
intended?
If yes, what was the incentive for that, what's it good for?

-- 
Oğuz

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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-15  8:41 variable expanding to `*` matches a literal `*` in case cond. construct Oğuz
@ 2019-12-15 10:05 ` Andreas Kusalananda Kähäri
  2019-12-15 11:04   ` Oğuz
  0 siblings, 1 reply; 12+ messages in thread
From: Andreas Kusalananda Kähäri @ 2019-12-15 10:05 UTC (permalink / raw)
  To: Oğuz; +Cc: zsh-users

On Sun, Dec 15, 2019 at 11:41:38AM +0300, Oğuz wrote:
> Although one would expect it to print "match"
> 
>     zsh -c 'case foo in $1) echo match; esac' sh '*'
> 
> above command doesn't print anything; if `*` is a result of a variable
> expansion,
> it matches only a literal asterisk. All the other shells I could find
> (including ksh
> from 2010) does print "match". I know this is a compliancy issue and zsh
> doesn't
> claim to be compatible with any other shell, I really wonder; was this
> intended?
> If yes, what was the incentive for that, what's it good for?
> 
> -- 
> Oğuz

In zsh, I suppose you would use ${~1}

    $ zsh -c 'case foo in ${~1}) echo match; esac' sh '*'
    match
    $ zsh -c 'case foo in ${~1}) echo match; esac' sh '??'
    $ zsh -c 'case foo in ${~1}) echo match; esac' sh '???'
    match

From the manual:

${~spec}
       Turn on the GLOB_SUBST option for the evaluation of spec; if the
       `~' is doubled, turn it off.  When this option is set, the
       string resulting from the expansion will be interpreted as a
       pattern anywhere that is possible, such as in filename expansion
       and filename generation and pattern-matching contexts like the
       right hand side of the `=' and `!=' operators in conditions.

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-15 10:05 ` Andreas Kusalananda Kähäri
@ 2019-12-15 11:04   ` Oğuz
  2019-12-15 12:02     ` Andreas Kusalananda Kähäri
  0 siblings, 1 reply; 12+ messages in thread
From: Oğuz @ 2019-12-15 11:04 UTC (permalink / raw)
  To: andreas.kahari; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 411 bytes --]

15 Aralık 2019 Pazar tarihinde Andreas Kusalananda Kähäri <
andreas.kahari@abc.se> yazdı:
>
> In zsh, I suppose you would use ${~1}
>

Thank you. But don't you think it would be better if GLOB_SUBST was enabled
by default and `${~spec}` was for disabling it for an individual expansion?
The way it is it doesn't seem possible to write a portable script which
works on zsh as well.


-- 
Oğuz

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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-15 11:04   ` Oğuz
@ 2019-12-15 12:02     ` Andreas Kusalananda Kähäri
  2019-12-15 12:50       ` Oğuz
  0 siblings, 1 reply; 12+ messages in thread
From: Andreas Kusalananda Kähäri @ 2019-12-15 12:02 UTC (permalink / raw)
  To: Oğuz; +Cc: zsh-users

On Sun, Dec 15, 2019 at 01:04:25PM +0200, Oğuz wrote:
> 15 Aralık 2019 Pazar tarihinde Andreas Kusalananda Kähäri <
> andreas.kahari@abc.se> yazdı:
> >
> > In zsh, I suppose you would use ${~1}
> >
> 
> Thank you. But don't you think it would be better if GLOB_SUBST was enabled
> by default and `${~spec}` was for disabling it for an individual expansion?
> The way it is it doesn't seem possible to write a portable script which
> works on zsh as well.
> 
> 
> -- 
> Oğuz

The fact that zsh does not (by default) perform splitting nor globbing
on unquoted variables is a well known feature of this shell and one of
the things that sets it apart from more conventional POSIX-like shells
like bash or ksh.

Wanting to write scripts that "works with any shell" is IMHO a
misdirected efforti (why would you want to run code written for one
language with the interpreter for another?). However, since this is
something that people seems to want to do, zsh provides emulation of sh:

    $ zsh --emulate sh -c 'case foo in $1) echo match; esac' sh '*'
    match

See the "emulate" built-in utility in the zshbuiltins(1) manual.

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-15 12:02     ` Andreas Kusalananda Kähäri
@ 2019-12-15 12:50       ` Oğuz
  2019-12-15 22:49         ` Eric Cook
                           ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Oğuz @ 2019-12-15 12:50 UTC (permalink / raw)
  To: andreas.kahari; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1632 bytes --]

On Sun, Dec 15, 2019 at 3:02 PM Andreas Kusalananda Kähäri <
andreas.kahari@abc.se> wrote:

>
> The fact that zsh does not (by default) perform splitting nor globbing
> on unquoted variables is a well known feature of this shell and one of
> the things that sets it apart from more conventional POSIX-like shells
> like bash or ksh.
>
>
Well-known by experienced users. Since MacOS switched to zsh, and MacOS's
userbase mostly consists of people who have no idea what they're doing when
it comes to command line; I think it's not unreasonable to expect them to
complain about how shell scripts/commands they find on the internet doesn't
work on their precious cheese graters. That's my concern, maybe I'm wrong,
I don't know.


> Wanting to write scripts that "works with any shell" is IMHO a
> misdirected efforti (why would you want to run code written for one
> language with the interpreter for another?).


I agree with that, but still, most shells out there are compatible with
each other to some extent. I just expected zsh too to be so.

However, since this is
> something that people seems to want to do, zsh provides emulation of sh:
>
    $ zsh --emulate sh -c 'case foo in $1) echo match; esac' sh '*'
>     match
>
> See the "emulate" built-in utility in the zshbuiltins(1) manual.
>

I guess this is a new feature. The latest version available on Ubuntu 18.04
repo doesn't have such an option as `--emulate`, you need to call `emulate`
from within the script; which is even worse.

Once again, I'm dissapointed with and somewhat annoyed by zsh.

Thanks again.

-- 
Oğuz

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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-15 12:50       ` Oğuz
@ 2019-12-15 22:49         ` Eric Cook
  2019-12-15 23:27         ` Dominik Vogt
  2019-12-16  0:03         ` dana
  2 siblings, 0 replies; 12+ messages in thread
From: Eric Cook @ 2019-12-15 22:49 UTC (permalink / raw)
  To: zsh-users

On 12/15/19 7:50 AM, Oğuz wrote:

> Well-known by experienced users.
and non-experienced users.

> Since MacOS switched to zsh, and MacOS's
> userbase mostly consists of people who have no idea what they're doing when
> it comes to command line; I think it's not unreasonable to expect them to
> complain about how shell scripts/commands they find on the internet doesn't
> work on their precious cheese graters. That's my concern, maybe I'm wrong,
> I don't know.

That falls on your vendor's hands. forcing a program onto you without educating you about it.



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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-15 12:50       ` Oğuz
  2019-12-15 22:49         ` Eric Cook
@ 2019-12-15 23:27         ` Dominik Vogt
  2019-12-16  0:02           ` Perry Smith
  2019-12-16  0:03         ` dana
  2 siblings, 1 reply; 12+ messages in thread
From: Dominik Vogt @ 2019-12-15 23:27 UTC (permalink / raw)
  To: zsh-users

On Sun, Dec 15, 2019 at 03:50:20PM +0300, O??uz wrote:
> On Sun, Dec 15, 2019 at 3:02 PM Andreas Kusalananda Kähäri <
> andreas.kahari@abc.se> wrote:
> Well-known by experienced users. Since MacOS switched to zsh, and MacOS's
> userbase mostly consists of people who have no idea what they're doing when
> it comes to command line; I think it's not unreasonable to expect them to
> complain about how shell scripts/commands they find on the internet doesn't
> work on their precious cheese graters. That's my concern, maybe I'm wrong,
> I don't know.

These features are why we "experienced users" prefer zsh.  If it
worked exactly like the Posix shell, what would be the point in
using zsh?

> > Wanting to write scripts that "works with any shell" is IMHO a
> > misdirected efforti (why would you want to run code written for one
> > language with the interpreter for another?).
>
> I agree with that, but still, most shells out there are compatible with
> each other to some extent. I just expected zsh too to be so.

What you normally need are not scripts compatible with every
shell, but *portable* scripts that run on any system.  Your best
bet ist to put

 #!/bin/sh
 (or /bin/bash for bash based systems; Linux etc.)

at the beginning of the script and make it executable. The manual
of autoconf has a chapter about writing portable shell scripts.

  https://www.gnu.org/software/autoconf/manual/autoconf-2.64/html_node/Portable-Shell.html

I recommend to read it, it lists many differences between shells
and is really helpful if you ever write software that must compile
on many systems.

> > See the "emulate" built-in utility in the zshbuiltins(1) manual.
>
> I guess this is a new feature. The latest version available on Ubuntu 18.04
> repo doesn't have such an option as `--emulate`, you need to call `emulate`
> from within the script; which is even worse.

What is actually the point in feeding scripts that have been
written for one shell to another?  Posix shells have (by
specification) some bugs that make scripting harder than
necessary.  Zsh replaces these bugs with sensible behaviour that
makes writing complex scripts for zsh much easier than for the
Posix shell, bash and others.

Some of zsh's strength are:

 + Powerful interactive mode
 + Advanced scripting

but if you're looking for something that works everywhere, /bin/sh
or /bin/bash is the better choice.

Ciao

Dominik ^_^  ^_^

--

Dominik Vogt

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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-15 23:27         ` Dominik Vogt
@ 2019-12-16  0:02           ` Perry Smith
  0 siblings, 0 replies; 12+ messages in thread
From: Perry Smith @ 2019-12-16  0:02 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 801 bytes --]



> On Dec 15, 2019, at 5:27 PM, Dominik Vogt <dominik.vogt@gmx.de> wrote:
> 
> What you normally need are not scripts compatible with every
> shell, but *portable* scripts that run on any system.  Your best
> bet ist to put
> 
> #!/bin/sh
> (or /bin/bash for bash based systems; Linux etc.)

Also, if you don’t put #!, the script is executed by “sh” — not
$SHELL

% cat /tmp/simple       
ps -p$$

(note there is no #!)

% /tmp/simple
  PID TTY           TIME CMD
24317 ttys000    0:00.01 sh /tmp/simple

note it is “sh” not zsh running the script

Also, zsh is only the default shell on MacOS for new users.  Existing
users, after an upgrade, still use the same shell as they did before
(this is according to the documentation which I’ve not verified).



[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2966 bytes --]

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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-15 12:50       ` Oğuz
  2019-12-15 22:49         ` Eric Cook
  2019-12-15 23:27         ` Dominik Vogt
@ 2019-12-16  0:03         ` dana
  2019-12-16  0:23           ` Oğuz
  2 siblings, 1 reply; 12+ messages in thread
From: dana @ 2019-12-16  0:03 UTC (permalink / raw)
  To: Oğuz; +Cc: andreas.kahari, Zsh Users

On 15 Dec 2019, at 06:50, Oğuz <oguzismailuysal@gmail.com> wrote:
> Well-known by experienced users. Since MacOS switched to zsh, and MacOS's
> userbase mostly consists of people who have no idea what they're doing when
> it comes to command line; I think it's not unreasonable to expect them to
> complain about how shell scripts/commands they find on the internet doesn't
> work on their precious cheese graters.

Not to pile on, but, just to be clear, since a lot of people still seem
confused on this point, or at least they're imagining unlikely scenarios:

Apple have changed their default *log-in shell* to zsh. /bin/sh is still
/bin/bash (though it seems like they might switch to dash in the future?), and
both of those still work exactly the way they did before. You still need to go
out of your way to write scripts that run under zsh. Even if you use zsh to
run a shell script without an interpreter directive, it will run it with
/bin/sh.

It's true that commands you copy and paste into your shell from the Internet
may not work if they use certain bashisms or (probably ill-conceived) features
of POSIX sh, but

(a) in my experience it's very rare that you're asked to interactively enter
    commands that make use of features that differ between zsh and bash/sh
    (i certainly don't see case/esac used much on the command line),

(b) it was *always* the case that those commands might not work on any given
    machine — the person giving the command has no idea if whoever they're
    instructing is using tcsh or fish or anything else, they can't just assume
    that it's bash or even Bourne-like.

On 15 Dec 2019, at 06:50, Oğuz <oguzismailuysal@gmail.com> wrote:
> I guess this is a new feature. The latest version available on Ubuntu 18.04
> repo doesn't have such an option as `--emulate`, you need to call `emulate`
> from within the script; which is even worse.

I think this was added in zsh 5.5, which was released a little too late to
get added to Bionic. Eoan and Focal are currently up-to-date.

dana


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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-16  0:03         ` dana
@ 2019-12-16  0:23           ` Oğuz
  2019-12-16  0:28             ` Mikael Magnusson
  2019-12-16  5:25             ` Lewis Butler
  0 siblings, 2 replies; 12+ messages in thread
From: Oğuz @ 2019-12-16  0:23 UTC (permalink / raw)
  To: dana; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 827 bytes --]

16 Aralık 2019 Pazartesi tarihinde dana <dana@dana.is> yazdı:
>
> Apple have changed their default *log-in shell* to zsh. /bin/sh is still
> /bin/bash (though it seems like they might switch to dash in the future?),
> and
> both of those still work exactly the way they did before. You still need
> to go
> out of your way to write scripts that run under zsh. Even if you use zsh to
> run a shell script without an interpreter directive, it will run it with
> /bin/sh.
>

Thanks, this is something I didn't know. So the conclusion is;
1. One should never, ever expect zsh to be compatible with other shells
since it has to suck, just as its users,
2. Apple doesn't force zsh, and a proper shell is still available, so no
need to worry.

This is my last post to this mailing list, thanks.



-- 
Oğuz

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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-16  0:23           ` Oğuz
@ 2019-12-16  0:28             ` Mikael Magnusson
  2019-12-16  5:25             ` Lewis Butler
  1 sibling, 0 replies; 12+ messages in thread
From: Mikael Magnusson @ 2019-12-16  0:28 UTC (permalink / raw)
  To: Oğuz; +Cc: dana, Zsh Users

On 12/16/19, Oğuz <oguzismailuysal@gmail.com> wrote:
> 16 Aralık 2019 Pazartesi tarihinde dana <dana@dana.is> yazdı:
>>
>> Apple have changed their default *log-in shell* to zsh. /bin/sh is still
>> /bin/bash (though it seems like they might switch to dash in the
>> future?),
>> and
>> both of those still work exactly the way they did before. You still need
>> to go
>> out of your way to write scripts that run under zsh. Even if you use zsh
>> to
>> run a shell script without an interpreter directive, it will run it with
>> /bin/sh.
>>
>
> Thanks, this is something I didn't know. So the conclusion is;
> 1. One should never, ever expect zsh to be compatible with other shells
> since it has to suck, just as its users,
> 2. Apple doesn't force zsh, and a proper shell is still available, so no
> need to worry.
>
> This is my last post to this mailing list, thanks.

If all shells worked exactly the same, what would be the purpose of
having more than one to choose from? Zsh doesn't fall into the same
traps of traditional sh like bash did, and it is possible to write
working scripts without using horribly convoluted constructs. If you
think that "sucks", that is your loss. Looking forward to not getting
a reply to this since you've already sent your last post to this
mailing list, you're welcome.

-- 
Mikael Magnusson

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

* Re: variable expanding to `*` matches a literal `*` in case cond. construct
  2019-12-16  0:23           ` Oğuz
  2019-12-16  0:28             ` Mikael Magnusson
@ 2019-12-16  5:25             ` Lewis Butler
  1 sibling, 0 replies; 12+ messages in thread
From: Lewis Butler @ 2019-12-16  5:25 UTC (permalink / raw)
  To: Zsh Users

On 15 Dec 2019, at 17:23, Oğuz <oguzismailuysal@gmail.com> wrote:
> This is my last post to this mailing list, thanks.

<https://www.youtube.com/watch?v=W7gnpmOWBKo>

-- 
ɹןʇnqן
<mailto:lbutler@covisp.net>
tel:+1.303.219.0564




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

end of thread, other threads:[~2019-12-16  5:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-15  8:41 variable expanding to `*` matches a literal `*` in case cond. construct Oğuz
2019-12-15 10:05 ` Andreas Kusalananda Kähäri
2019-12-15 11:04   ` Oğuz
2019-12-15 12:02     ` Andreas Kusalananda Kähäri
2019-12-15 12:50       ` Oğuz
2019-12-15 22:49         ` Eric Cook
2019-12-15 23:27         ` Dominik Vogt
2019-12-16  0:02           ` Perry Smith
2019-12-16  0:03         ` dana
2019-12-16  0:23           ` Oğuz
2019-12-16  0:28             ` Mikael Magnusson
2019-12-16  5:25             ` Lewis Butler

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