grep, shopt:dotglob and (hidden) dot files


i thought grep was broken, but it’s not. see below:

james@dazzle:~$ echo $0
bash
james@dazzle:~$ echo 'hello world' > .hello
james@dazzle:~$ grep 'hello world' *
james@dazzle:~$ grep 'hello world' .*
.hello:hello world
james@dazzle:~$ shopt | grep dotglob
dotglob            off
james@dazzle:~$ shopt -s dotglob
james@dazzle:~$ shopt | grep dotglob
dotglob            on
james@dazzle:~$ grep 'hello world' *
.hello:hello world
james@dazzle:~$ shopt -u dotglob
james@dazzle:~$ shopt | grep dotglob
dotglob            off
james@dazzle:~$ rm .hello
james@dazzle:~$

the problem as it turns out is that the glob character `*’ (the asterisk) doesn’t expand to include dot files unless you have the shopt variable set. so you can either use to workaround shown above or set it. personally i’ll keep mine off.


You can follow James on Mastodon for more frequent updates and other random thoughts.
You can follow James on Twitter for more frequent updates and other random thoughts.
You can support James on GitHub if you'd like to help sustain this kind of content.
You can support James on Patreon if you'd like to help sustain this kind of content.

Links...

M

Comments

Nothing yet.


Post a comment



(sorry but the spammers were getting too crazy!)

Thank you

Your comment has been submitted and will be published if it gets approved.

Click here to see the patch you generated.

OK