Strange wildcharacter * behavior in shell script

In my shell script, I have the following code

echo * | tr ' ' '\n'

Here I noticed that although I used *, it skipped hidden files (. *) After that I tried to make an obvious change

echo .* | tr ' ' '\n'

This solved my problem with hidden files. But I'm just interested in this strange behavior *

Because. * is a subset *
desired output

  • echo * → All files, including hidden files

  • echo. * → All hidden files

  • echo [^.] * → All non-hidden files (currently echo *)

Therefore, echo * behaves like echo [^.] *

How to get a complete list of files, including hidden files, using echo. Similarly, there was an output for ls and dir, although ls -a gave the desired outputs

+5
source share
2

, '. , dotglob. . ". .

.* *,

echo .* * | tr ' ' '\n'

dotglob

shopt -s dotglob
echo * | tr ' ' '\n'

- . ...

+3

glob * , , . .* .

. . zsh setopt dotglob (POSIX), glob dotfiles . bash shopt -s dotglob. , , POSIX .

, , , , find . -maxdepth 1 ( , , echo * .* , , - glob , ).

+6

All Articles