brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: shopt globskipdots decides whether .* matches the . and .. entries

Shell
~/tips/tip-bash-globskipdots-dotfiles-pattern

shopt globskipdots

Controls whether a pattern like .* also matches the current and parent folder entries.

The pattern .* looks like it means “all hidden files”. Whether it also catches . and .. depends on one bash option, and it is worth knowing which way yours is set.

shopt globskipdots

The manual says that with globskipdots set, filename expansion never matches . and .., even if the pattern begins with a dot, and that the option is enabled by default. In a folder with one hidden file called .hid and one called visible, bash 5.2.21 gives this:

echo .*
.hid
shopt globskipdots
globskipdots   	on
shopt -u globskipdots
echo .*
. .. .hid

With the option switched off, the same pattern returned the two folder entries as well. A command that acts on every match would then be handed . and .. as well, so it is worth knowing which way your shell is set.

Turn it back on with shopt -s globskipdots. Both directions of the switch only affect the current shell session, so put it in your startup file if you want it fixed.

The caveat is portability. The option is documented in the current bash manual and was present in bash 5.2.21; other versions and shells may lack it. A script that has to run in any shell should not depend on it. Using .[!.]* as a pattern is one alternative; in the same folder it prints just .hid. It would miss names that start with two dots, such as ..foo, so it is not a perfect replacement either.

Further reading: Bash reference manual

More Shell tips zmv -n '(*).log' '$1.txt' zoxide query -ls project f=$(mktemp --suffix=.json) echo $EPOCHSECONDS docker compose logs --tail 50 web # now at the top of a clean screen All Shell tips (78) All topics

Link