Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[ksh] Availability of a 'nullglob' feature?

48 views
Skip to first unread message

Janis Papanagnou

unread,
Jul 3, 2021, 10:30:13 AM7/3/21
to
The lack of a 'nullglob' feature in Kornshell made it necessary to use
clumsy workarounds (like file-testing on the [un-]expanded pattern).
The ksh93u+ (also ksh93u+m) seems not to have any supporting functions.
Is that observation correct? Are there any [nicer] workarounds?

Janis

marrgol

unread,
Jul 3, 2021, 6:12:12 PM7/3/21
to
I think you could try sub-patterns (see man page), e.g. using
'~(N)*.txt' or ~(N:*.txt) pattern instead of '*.txt' for filename
generation returns an empty list instead of literal '*.txt' when
there's no file or directory ending with '.txt' available.


--
mrg

Janis Papanagnou

unread,
Jul 3, 2021, 7:02:00 PM7/3/21
to
Thanks, that's it.

Looking that up in the man page also lead me to the answer of another
pattern related question I had two months ago; thanks also for that. :-)

Janis

John McCue

unread,
Jul 4, 2021, 2:10:44 PM7/4/21
to
I can only guess what 'nullglob' is (never heard of it).

But on AIX and OpenBSD ksh, you have 'set -o noglob' or
command argument '-f'.

Maybe that is the same as nullglob ?

Janis Papanagnou

unread,
Jul 4, 2021, 3:22:37 PM7/4/21
to
On 04.07.2021 20:10, John McCue wrote:
> Janis Papanagnou <janis_pa...@hotmail.com> wrote:
>> The lack of a 'nullglob' feature in Kornshell made it necessary to use
>> clumsy workarounds (like file-testing on the [un-]expanded pattern).
>> The ksh93u+ (also ksh93u+m) seems not to have any supporting functions.
>> Is that observation correct? Are there any [nicer] workarounds?
>
> I can only guess what 'nullglob' is (never heard of it).

Sorry for not having explained that.

It's a shell option that you can activate in _bash_. If globbing is
activated - you can control that with the 'noglob' option that you
mention below - then any globbing pattern will expand to filenames
that match, unless there is no match, then the pattern will persist.
This is usually not what one wants. Activating the non-standard
option 'nullglob' will result in an empty list as expansion result
in that case of no matching files.

Janis

>
> But on AIX and OpenBSD ksh, you have 'set -o noglob' or
> command argument '-f'.
>
> Maybe that is the same as nullglob ?

The 'noglob' controls activation of file matching where globbing
characters are present, the 'nullglob' controls how the no-match
condition will be handled, unexpanded pattern vs. empty list.

Janis

John McCue

unread,
Jul 5, 2021, 11:51:51 AM7/5/21
to
Janis Papanagnou <janis_pa...@hotmail.com> wrote:
> On 04.07.2021 20:10, John McCue wrote:
>> Janis Papanagnou <janis_pa...@hotmail.com> wrote:
>>> The lack of a 'nullglob' feature in Kornshell made it necessary to use
>>> clumsy workarounds (like file-testing on the [un-]expanded pattern).
>>> The ksh93u+ (also ksh93u+m) seems not to have any supporting functions.
>>> Is that observation correct? Are there any [nicer] workarounds?
>>
>> I can only guess what 'nullglob' is (never heard of it).
>
> Sorry for not having explained that.

That is fine, I could have googled it but was lazy and did
not want to fire up Firefox.

But your explanation made more since then what I found in
google :)

<snip>
0 new messages