I am a newbie for shell script.
I noticed that for command like:
tar cf test.tar *TEST* *TEST2*
sh and bash will expand TEST to a list of file names, while csh will not.
I want the shell not to expend, how can I do this?
Use ‘ or ” will lead to other problems. If there is files match pattern *TEST*, but no files match *TEST2*,
then the tar will fail.
[EDIT]I think this is an expend difference between bash and csh.
When no pattern found for *TEST*, csh will expend to “”, while bash will expend to ‘TEST‘ (add quote char).
From
man bash:For example:
This is approximately equivalent to the
cshbehaviour:The difference is that
cshwill return an error if all of the filename patterns on a line fail to match anything:while
bashwill just return an list of tokens to the command, leading to oddities such as this:*TEST4*and*TEST2*both return nothing; so thelscommand believes it has been called with no arguments and just gives a listing of the directory. In your example, tar would (rightly) complain that it’s being given no files to work on.