2

I've got script, it must go through files to get specific lines from them. Filename get from variable, for example $FILENAME and we've got such situation:

cat /path/$FILENAME

but when FILENAME==*.some.file there is a problem. File *.some.file really exist, but cat lists all files by mask *.some.file (first.some.file second.some.file *.some.file fourth.some.file and so on) single quotes on path prevent include of variable.

Any ideas how to cat (or grep) only one *.some.file?

3 Answers3

6

Use double quotes. This will expand the variable, but not any embedded wildcards.

cat /path/"$FILENAME"
Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
3
cat "/path/to/$FILENAME"

will not expand * to a glob.

amphetamachine
  • 852
  • 1
  • 8
  • 14
2

cat \*.some.file will escape the * so it's treated as a literal character.

Also cat '*.some.file' will have a similar effect. In both cases, it prevents bash from expanding the * to a list of matching files.

SmallClanger
  • 9,127
  • 1
  • 32
  • 47