Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add nullglob to fix count when no files match #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ Don’t use `ls`.

```shell
# Greedy example.
shopt -s nullglob
for file in *; do
printf '%s\n' "$file"
done
Expand All @@ -848,6 +849,7 @@ done
for dir in ~/Downloads/*/; do
printf '%s\n' "$dir"
done
shopt -u nullglob

# Brace Expansion.
for file in /path/to/parentdir/{file1,file2,subdir/file3}; do
Expand Down Expand Up @@ -1005,14 +1007,17 @@ count() {

```shell
# Count all files in dir.
$ shopt -s nullglob
$ count ~/Downloads/*
232

# Count all dirs in dir.
$ shopt -s nullglob
$ count ~/Downloads/*/
45

# Count all jpg files in dir.
$ shopt -s nullglob
$ count ~/Pictures/*.jpg
64
```
Expand Down