I just need help understanding how DOS and BASH handle globs. All I ever see is the output but it's not giving me any knowledge on the whole process. How does dir * interpret the wildcard differently then ls *?

DOS uses "dir *" to match on the file name, such as "dir D*" will run for the currently directory and show all files/dirs beginning with D:

C:\Documents and Settings\scott.SCOTTIE>echo D*
D*

C:\Documents and Settings\scott.SCOTTIE>dir D*
 Directory of C:\Documents and Settings\scott.SCOTTIE
07/22/2009  05:20 PM    <DIR>          Desktop

Linux uses the * to complete file names. so ls D* is equivelant to doing "ls ./Desktop/" in this case and it actually lists the contents of the directory and not the directory itself:

sk@sk:/tmp$ mkdir -p Desktop/test1
sk@sk:/tmp$ echo D*
Desktop
sk@sk:/tmp$ ls D*
test1

As you can see "dir D*" in dos lists the contents of the CWD with files beginning in D, whereas bash expands those directories and lists their contents.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.