Why does '[: print:] [: blank:]' become 'in' if the file 'in' exists in the current directory?

This is normal? I tried (long story ... it all started with a bad quote on something else) with bash, dash and ksh. In all cases, I get:

$ echo [:print:][:blank:] [:print:][:blank:] $ touch in $ echo [:print:][:blank:] in 

I thought this had something to do with 'in', which is a substring of 'print', but (say) 'pr' does not do this:

 $ rm in; touch pr $ echo [:print:][:blank:] [:print:][:blank:] 

In addition, removing the "empty" gets rid of this:

 $ touch in; echo [:print:] [:print:] 

I am completely lost. Thanks in advance for your help!

+4
source share
2 answers

[:print:][:blank:] considered as a glob template, so any file names that match it will be printed as if you said echo * (try in an empty directory).

[:print:] interpreted as "one of the characters { : , p , r , i , n , t }" and similarly for [:blank:] ; therefore, a match with in , but not pr .

( pr will match [:print:][:print:] , though.)

+2
source

This is because the shell expands the path name and replaces the pattern [:print:][:blank:] alphabetically sorted list of file names matching the pattern. If no matching file names are found, the word remains unchanged. So, if your directory contains a file named in , it is matched because it matches the pattern.

Similarly, if you had files named pb , ta , etc., they would also be matched. However, pr does not match the pattern.

These file names are then transferred to echo and printed on the screen.

See the bash man page for more information.

+2
source

All Articles