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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s