On Fri, Nov 19, 2021 at 08:58:00PM +1100, Reuben ua Bríġ wrote:
> > Date: Fri, 19 Nov 2021 10:23:51 +0100
> > From: Andreas Kusalananda Kähäri <[email protected]>
> > 
> > What was the thing about "/" and "ti"?
> 
> I might a lot of typos. by "ti" I meant "2". I had the glob "2/*" which
> includes a "/". My point was this does not generally preclude special
> interpretation (someone suggested including a "/" for globs with "rm").

Someone probably suggested using ./ as a prefix to any glob that
otherwise may result in words possibly starting with a dash, such as *
or *.c would possibly do.  Using ./* or ./*.c or similar in a loop would
ensure that each generated word is starting with ./ rather than possibly
a dash.

        for name in ./*; do
                # Will not mistake "$name" as a set of options.
                # Because "$name" always starts with ./
                utility "$name"
        done

or, using -- instead:

        for name in *; do
                # Will not mistake "$name" as a set of options.
                # Because -- disables option parsing.
                utility -- "$name"
        done

> 
> 
> > Are you talking about zsh here? Or do you know something about ksh?
> > I know -a{1,2,3} -> -a1 -a2 -a3 but nothing like -a{*} -> -a*1 -a*2
> > ...  
> 
> > I'm not sure I understand what you want -a{*} to do.  Are "1", "2",
> > etc. files?  If so, *(P[-a]) in zsh, as already mentioned.
> 
> The point is ksh expands "-a{1,2,3}" to "-a1 a2 a3". I had hoped it

The ksh shell would expand -a{1,2,3} to the three strings -a1, -a2, and
-a3.

> might expand "-a{*}" to "-a1 -a2 -a3" in a directory containing the
> files "a", "b", "c".

That makes no sense.  You could get -a a -a b -a c from *(P[-a]) in zsh.

> > The -c option to cc does not take arguments.  If you just want to list
> > all C files on the command line:
> 
> This was a rather bad toy example. On OpenBSD I overuse a default
> make(1) file so I have forgotten how to actually call cc(1).
> Maybe this will help you see the point I was making:
> 
>       f=* sed -f$f

In sh (inserts -f as a separate argument before each name that * expands
to):

        set -- *
        for name do
                set -- "$@" -f "$name"
                shift
        done

        sed "$@"

In OpenBSD ksh (same result as above):

        unset -v args
        for name in *; do
                set -A args -- "${args[@]}" -f "$name"
        done

        sed "${args[@]}"

In bash (prepends the string -f directly to each name):

        names=(*); sed "${names[@]/#/-f}"

In zsh (as sh and ksh):

        sed *(P[-f])

> 
> I think sed(1) might actually be what first gave me the idea. I had a
> bunch of scripts and a bunch of inputs, and some expressions, and I
> thought, "wouldnt it be neat if I could do it this way..."
> 
> > The es shell is available for OpenBSD.  It's not quite rc, but may be
> > close enough.
> 
> Strangely enough I have an "rc" package installd, and a ports/plan9/rc
> directory. I havent upgraded and also have a "plan9port" package
> installd, so maybe that has something to do with that. I also have
> butchered my install somewhat, so maybe it is that.

If you have plan9port installed, just prefix commands by 9 to get the
Plan9 variant, e.g. use "9 rc" to start the rc shell, or use "9 sed" to
use Plan9 sed.

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

.

Reply via email to