Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

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

cat /path/"$FILENAME"
share|improve this answer

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.

share|improve this answer
cat "/path/to/$FILENAME"

will not expand * to a glob.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.