Hi experts !
I'm just playing with bash's "extglob" option:
$ shopt -s extglob
$ echo /etc/ssh/sshd_config?(.d)
/etc/ssh/sshd_config /etc/ssh/sshd_config.d
$
So far, so good. But now I want to catch the global file and potential custom files.
$ echo /etc/ssh/sshd_config?(.d/*)
/etc/ssh/sshd_config
$
I would accept this if there were no files in the directory but in fact, there is one. Where's my brain fault?
And to my understanding, ksh behaves like this by default, right?
On Tue, 17 Feb 2026 12:57:06 +0100, Frank Winkler wrote:
Hi experts !
I'm just playing with bash's "extglob" option:
$ shopt -s extglob
$ echo /etc/ssh/sshd_config?(.d)
/etc/ssh/sshd_config /etc/ssh/sshd_config.d
$
So far, so good. But now I want to catch the global file and potential
custom files.
$ echo /etc/ssh/sshd_config?(.d/*)
/etc/ssh/sshd_config
$
I would accept this if there were no files in the directory but in fact,
there is one. Where's my brain fault?
According to the bash manpage,
"If the extglob shell option is enabled using the shopt builtin, several
extended pattern matching operators are recognized."
...
" ?(pattern-list)
Matches zero or one occurrence of the given patterns"
Ok, so your "given pattern" is ".d/*". Do you have any files that have a ".d/*" suffix? I thought not.
Try moving the /* to outside of the patternlist, as in--
echo /etc/ssh/sshd_config?(.d)/*
HTH
And to my understanding, ksh behaves like this by default, right?
I have no idea, I don't use ksh. Sorry
On 17.02.2026 17:43, Lew Pitcher wrote:
So, your "?(.d/*) expression cant work, because none of thecomponents of
a pathname may contain a '/' character, and, thus, will never match the
expression.
Still trying to figure this out completely ...
But what's the solution then? Isn't there a closed expression for that?
Do I really have to use the uncool
-a /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
way?
TIA
-a-a-a-aFrank
On 2026-02-17 17:53, Frank Winkler wrote:
On 17.02.2026 17:43, Lew Pitcher wrote:
-a-a>So, your "?(.d/*) expression cant work, because none of the
components of
-a-a>a pathname may contain a '/' character, and, thus, will never match
the
-a-a>expression.
And, concerning the upthread question, Kornshell behaves the same.
Still trying to figure this out completely ...
Simply put; don't use slashes - the special character in the Unix
file system - in "extended" _*file globbing* patterns_ (as quoted
by Lew).
In Ksh you can of course still use it in _*text* pattern matching_.
$ x='Projects/Algol68' ; [[ $x == ?(*/)Algol68 ]] && echo match
match
But what's the solution then? Isn't there a closed expression for
that? Do I really have to use the uncool
-a-a /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
way?
If your task is actually two-fold
-a-a display file sshd_config by globbing
and
-a-a display any file under "/etc/ssh/sshd_config.d/" by globbing
then yes.
If you want to match _path-*strings*_ (including optional slashes)
then do text-processing, i.e. create the path names text and grep
-a find ... | grep <some-pattern-including-slahses>
I don't think this approach is "cooler" (whatever you meant by
"uncool"), but the concept should be clearly differentiated now.
But what's the solution then? Isn't there a closed expression
for that? Do I really have to use the uncool
/etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
way?
Do I really have to use the uncool
/etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
On Tue, 17 Feb 2026 17:53:06 +0100, Frank Winkler wrote:
Do I really have to use the uncool
/etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
ldo@theon:~> echo /etc/ssh/sshd_config{,.d/*}
/etc/ssh/sshd_config /etc/ssh/sshd_config.d/20-systemd-userdb.conf
Though I think the alternatives-within-braces thing is a bash-ism ...
But what's the solution then? Isn't there a closed
expression for that? Do I really have to use the
uncool
/etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
On 18.02.2026 09:51, I wrote:
Though I think the alternatives-within-braces thing is a bash-ism ...
It seems that it also works with ksh but no matter if bash or ksh, it
does need the "nullglob" feature to give the correct result.
That's easy to do in bash but how do I combine the brace expression with ksh's "~(N:)" (as there is no "nullglob" option)?
... I wasn't aware that [alternatives-within-braces] also works with
path names.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 59 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 18:03:51 |
| Calls: | 810 |
| Calls today: | 1 |
| Files: | 1,287 |
| D/L today: |
10 files (21,017K bytes) |
| Messages: | 193,396 |