Short version
Compare
dir *.txt
(list of all the files with extension txt)
and
echo *.txt
(just print *.txt)
How to make echo behave like dir with the * symbol?
Long version - A real case
Figure out this:
There is a directory with thousands of files names *.txt, each of them with numbers using the comma as a decimal separator. We want to convert all the commas inside the files into dots.
I know how to do it with perl, running just this single command on a shell like bash:
perl -pi -e "s/,/./g" *.txt
Now, do not focus on the perl script and options, just look at the trailing part of the command, that is
<command> <options> *.txt
Look at *.txt: I was assuming that it is expanded into a list of all the files with extension *.txt by the shell, so that the real command, in this case "perl", does not see *.txt: it should receieve directly the expanded list of existing files in the current directory.
Now this is true for shells like bash, but it does not happen on take command nor on cmd.
On the other hand, on take command some specific commands, such as dir, do accept the * symbol and it is their own responsibility to replace the pattern with a list of existing files.
How can I pass to an external command a list of existing files matching a given pattern?
Compare
dir *.txt
(list of all the files with extension txt)
and
echo *.txt
(just print *.txt)
How to make echo behave like dir with the * symbol?
Long version - A real case
Figure out this:
There is a directory with thousands of files names *.txt, each of them with numbers using the comma as a decimal separator. We want to convert all the commas inside the files into dots.
I know how to do it with perl, running just this single command on a shell like bash:
perl -pi -e "s/,/./g" *.txt
Now, do not focus on the perl script and options, just look at the trailing part of the command, that is
<command> <options> *.txt
Look at *.txt: I was assuming that it is expanded into a list of all the files with extension *.txt by the shell, so that the real command, in this case "perl", does not see *.txt: it should receieve directly the expanded list of existing files in the current directory.
Now this is true for shells like bash, but it does not happen on take command nor on cmd.
On the other hand, on take command some specific commands, such as dir, do accept the * symbol and it is their own responsibility to replace the pattern with a list of existing files.
How can I pass to an external command a list of existing files matching a given pattern?