I was messing around in terminal on Red Hat Linux, and when I typed the asterisk (*
) followed by return, and it executed one of the programs in my directory. Why?
My best guess is that Unix treated it as a wildcard so it executed the first alphabetic program.
Since my_program.exe
and one_of_my_programs.program
can be executed by simply typing the name of the file, the wildcard operator represents all the possible files. Since a program is first alphabetically, Unix executes it. Is this a correct judgement?
Best Answer
Your interpretation is correct. The rest of the files will be presented as its parameter list.
Note that it will do this only if the program has the executable bit set, and the current directory is in the
PATH
list.A couple of notes which may help understanding:-
./*
then thePATH
entry is not a requirement.. *
or. ./*
and the first matching file is a script, then it need not be executable, nor need the current directory be inPATH
(may not be true for shells other thanbash
).