On Sun, Oct 5, 2025, at 3:31 AM, Michael Gasanenko wrote:
> **Proposal:** Let `.../` (three dots) replace any number of `../`
> (parent directory) symbols, provided that the file name that follows
> the dots exists somewhere above in the directory tree.
>
> [...]
>
> Three dots expansion MUST be performed after variable expansion but
> before passing paths to file I/O functions.
I think it would be a bad idea to add a fake, bash-specific pathname
component that looks like "." and "..", which are not bash-specific.
The following doesn't work (error-checking omitted), but it would
be interesting if it did:
shopt -s extglob
files=(*(../)foo)
echo "${files[-1]}"
zsh supports something similar [*]:
setopt EXTENDED_GLOB
echo (../)#foo(Y1)
> Note that we allow any file, even an ordinary file, to be mentioned
> between `.../` and `/..` , that is, in `.../foo/..`, `foo` need not be
> a directory (note that `ordinary_file/..` is not allowed in modern
> bash).
This is not due to bash; it is a fundamental part of how pathname
resolution works, even in other programs.
https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap04.html#tag_04_16
I think it would be a bad idea to override the standard behavior
of ".." with bash-specific behavior.
> Extension: `...../` (five dots) is equivalent to `../../.../` (two
> level-ups and three dots), e.g. `.../build.gradle/...../build.gradle`
> is equivalent to `.../build.gradle/../../.../build.gradle`
https://theonion.com/fuck-everything-were-doing-five-blades-1819584036/
> ## Appendix 2: the same functionality in Gradle/Groovy
>
> Build systems like Gragle would also benefit from both the three dots
> syntax and the very idea that such ancestor tree search is possible.
>
> [...]
>
> With the proposed three dots notation, it would be just:
> ```Groovy
> buildscript {
> dependencies{
> classpath fileTree(dir: '.../anotherProject/build/libs',
> include: ['*.jar'])
> }
> }
> ```
What does this have to do with bash? Surely Groovy doesn't invoke
shells to expand path strings?
[*] This is a special case:
Note that grouping cannot extend over multiple directories:
it is an error to have a `/' within a group (this only
applies for patterns used in filename generation). There
is one exception: a group of the form (pat/)# appearing as
a complete path segment can match a sequence of directories.
For example, foo/(a*/)#bar matches foo/bar, foo/any/bar,
foo/any/anyother/bar, and so on.
https://zsh.sourceforge.io/Doc/Release/Expansion.html#Glob-Operators
--
vq