The difference is that one is a list and the other a sequence. {1,2,3}
expands to three specific elements, 1
,2
, and 3
. {1..3}
expands to the list of numbers between one and three. In this particular case, they are the same and you can use either of the two. file.*
will expand to all the files and directories in the current directory whose name starts with file.
. If you only have file.1
,file.2
and file.3
then that too is equivalent to the other two.
As for its causing problems, I don't see why. You might be thinking of
$ cat file.* > file.txt
cat: file.txt: input file is output file
That, however, is a completely different issue. The only other problem I can think of is that your shell might not list the files in the correct order. For example:
$ touch file1 file11 file2
$ echo file*
file1 file11 file2
To solve that, you can use zsh
instead of bash
(see here for details):
% echo f*(n)
file1 file2 file11
In general, the three approaches are not the same. It depends on what you want to do. In those cases where the three return the same output then, yes, you can use any of them. It makes no difference. All of these expansions are done by the shell and happen before they are passed to whatever command uses them.
cat file.[123] >file
file.*
is not dependent on the inodes. It always sorts them lexicographically, which could depend on your locate setting.file.{1..3}
which expands to all three whether or not they exist.cat
errors withfile.[123] not found
or something very useful.