Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
4
votes
1
answers
134
views
Bash extglob with ignored pattern
Suppose I have these files: ``` foo/bar/baz/test.js foo/bar/baz/test.min.js ``` If I run: ```sh shopt -s globstar shopt -s extglob echo foo/bar/**/*!(.min).js ``` ...that will nonetheless match the `test.min.js` file. How do I ignore it?
Suppose I have these files:
foo/bar/baz/test.js
foo/bar/baz/test.min.js
If I run:
shopt -s globstar
shopt -s extglob
echo foo/bar/**/*!(.min).js
...that will nonetheless match the test.min.js
file.
How do I ignore it?
lonix
(1965 rep)
Dec 13, 2024, 11:01 AM
• Last activity: Jan 6, 2025, 01:58 PM
6
votes
1
answers
3897
views
Why is the bash double star (globstar) operator often disabled by default?
It seems to be a very useful feature. But I had to learn that it is often disabled by default. I though about enabling it on my system. But there is probably a good reason why it is disabled. Without knowning that, it seems unwise to enable it. Therefore my question: Why is the bash double star oper...
It seems to be a very useful feature. But I had to learn that it is often disabled by default. I though about enabling it on my system. But there is probably a good reason why it is disabled. Without knowning that, it seems unwise to enable it. Therefore my question: Why is the bash double star operator often disabled by default?
I found multiple questions about how it is enabled, what the operator is named and how to use it. All of them mention that it has to be enabled first. But none of the questions explains *why* it is disabled by default.
user194860
(163 rep)
Apr 24, 2022, 04:25 PM
• Last activity: Jun 30, 2022, 08:52 AM
1
votes
2
answers
371
views
how to check for existence of multiple patterns in bash
i have several patterns that include ** wildcard, let them be: foo/**/bar.xml foo/**/baz.xml and i have an example dirtree: $ tree foo/ foo/ └── deep ├── baz.xml └── even └── deeper └── baz.xml what would be easiest way to check if any of those patterns is fulfilled? to be precise: return nonzero **...
i have several patterns that include ** wildcard, let them be:
foo/**/bar.xml
foo/**/baz.xml
and i have an example dirtree:
$ tree foo/
foo/
└── deep
├── baz.xml
└── even
└── deeper
└── baz.xml
what would be easiest way to check if any of those patterns is fulfilled? to be precise: return nonzero **only if none** is found. what I came up with so far is to use
globstar
and nullglob
. But ls
is not an option here, as if no pattern is satisfied, is lists current directory. So i had to utilize echo
, like this:
$ (shopt -s globstar nullglob; echo foo/**/bar.xml foo/**/baz.xml) | grep .
foo/deep/baz.xml foo/deep/even/deeper/baz.xml
$ echo $?
0
vs
$ (shopt -s globstar nullglob; echo foo/**/bar.xml foo/**/beque.xml) | grep .
$ echo $?
1
so yeah - it works. but maybe i missed something and there is **simpler/more elegant** way to achieve this?
murison
(163 rep)
Jun 14, 2022, 01:12 PM
• Last activity: Jun 15, 2022, 01:03 PM
2
votes
1
answers
878
views
GLOBIGNORE='**/dont_doc/**' does not work!
I wanted to create a glob expression to ignore any file inside a `dont_doc` directory, but when I tried using using `GLOBIGNORE` to do it, it did not work: ``` $ GLOBIGNORE='**/dont_doc/**' $ echo dont_doc/** dont_doc/customBlockHelpers.hbs.js dont_doc/RoClasses.js dont_doc/RoEnums.js dont_doc/RoMod...
I wanted to create a glob expression to ignore any file inside a
dont_doc
directory, but when I tried using using GLOBIGNORE
to do it, it did not work:
$ GLOBIGNORE='**/dont_doc/**'
$ echo dont_doc/**
dont_doc/customBlockHelpers.hbs.js dont_doc/RoClasses.js dont_doc/RoEnums.js dont_doc/RoModules.js dont_doc/RoTypes.js
this is what I want to happen:
dont_doc/doc.js #Fail
dont_doc/lol/doc.js #Fail
lol/dont_doc/doc.js #Fail
lol/dont_doc/lol/doc.js #Fail
lol.js #Succsed
index.html #Fail
oof/lol.js #Succsed
how do I fix this?
**Edit:** I also want to ignore the node_modules
folder
Errorbot1122 THE SECOND
(25 rep)
Nov 12, 2021, 05:38 PM
• Last activity: Nov 12, 2021, 07:19 PM
0
votes
1
answers
1254
views
How to use find with globs in a Bash shell script?
I'm trying to use `find` with *globs* in a Bash shell script. I've tried to both sourcing it and running it, but the command fails every time. ```bash #!/usr/bin/env bash # glob-test.sh - a script to test globs in find cd /to/a/windows/share-point find ./**/*Some/*Place/**/ -iname "*.pdf" # How abou...
I'm trying to use
find
with *globs* in a Bash shell script. I've tried to both sourcing it and running it, but the command fails every time.
#!/usr/bin/env bash
# glob-test.sh - a script to test globs in find
cd /to/a/windows/share-point
find ./**/*Some/*Place/**/ -iname "*.pdf"
# How about using foreign characters?
find ./**/*Söme/*Pläce/**/ -iname "*.pdf"
* From bash command line it works
* I have tried different way of quoting it.
* I have tried *sourcing* and *executing* the script.
* I have tried turning on/off the *globstar* shell option, both inside and outside the script, but still no go. (shopt -s/u globstar
)
What is the problem and how to fix it?
not2qubit
(1788 rep)
Apr 29, 2021, 05:38 PM
• Last activity: Apr 30, 2021, 07:37 PM
5
votes
1
answers
543
views
Can ** (bash's globstar) run out of memory?
Can using bash's globstar (`**`) operator cause an out of memory error? Consider something like: ``` for f in /**/*; do printf '%s\n' "$f"; done ``` When `**` is being used to generate an enormous list of files, assuming the list is too large to fit in memory, will bash crash or does it have a mecha...
Can using bash's globstar (
**
) operator cause an out of memory error? Consider something like:
for f in /**/*; do printf '%s\n' "$f"; done
When **
is being used to generate an enormous list of files, assuming the list is too large to fit in memory, will bash crash or does it have a mechanism to handle this?
I know I've run **
on humongous numbers of files and haven't noticed a problem, so I am assuming that bash will use something like temporary files to store some of the list as it is being generated. Is that correct? Can bash's **
handle an arbitrary number of files or will it fail if the file list exceeds what can fit in memory? If it won't fail, what mechanism does it use for this? Something similar to the temp files generated by sort
?
terdon
(251585 rep)
Mar 15, 2021, 12:36 PM
• Last activity: Mar 15, 2021, 04:00 PM
27
votes
3
answers
30079
views
bash globstar matching
I have this directory structure: ~/tmp/globstar ɀ find dir -type f dir/file.ext dir/subdir1/file.ext dir/subdir2/file.ext and, with the `globstar` option enabled in Bash, I can say: ~/tmp/globstar ɀ ls -1 dir/**/*.ext dir/subdir1/file.ext dir/subdir2/file.ext My question is: why is `dir/file.ext` ex...
I have this directory structure:
~/tmp/globstar ɀ find dir -type f
dir/file.ext
dir/subdir1/file.ext
dir/subdir2/file.ext
and, with the
globstar
option enabled in Bash, I can say:
~/tmp/globstar ɀ ls -1 dir/**/*.ext
dir/subdir1/file.ext
dir/subdir2/file.ext
My question is: why is dir/file.ext
excluded from this list?
Bash manual says this about globstar
:
> If set, the pattern ‘**’ used in a filename expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a ‘/’, only directories and subdirectories match.
“**zero**” in this paragraph let me with the impression that dir/file.ext
should have been included; unless I’m hopefully missing something.
Vlad GURDIGA
(373 rep)
Mar 2, 2014, 11:01 PM
• Last activity: Mar 15, 2021, 12:55 PM
Showing page 1 of 7 total questions