0

Suppose I have a filename in a variable.

FILENAME_VAR = "1000-Feature.mp4"

What is the bash command I can use to test that the filename in the variable $FILENAME_VAR contains the word Feature?

Zombo
  • 1
  • 55
  • 342
  • 375
chuacw
  • 1,393
  • 1
  • 21
  • 34

2 Answers2

2

One way to do it

if [[ $FILENAME_VAR =~ Feature ]]
then
  echo good
else
  echo bad
fi
Zombo
  • 1
  • 55
  • 342
  • 375
  • Steven, I tried your way, but it doesn't seem to work. What I'm testing is to see if the word "Feature" exists in the variable, not in the actual file. – chuacw Jun 12 '13 at 05:28
2
$ [[ $FILENAME_VAR = *Feature* ]] ; echo $?
0
$ [[ $FILENAME_VAR = *Feature2* ]] ; echo $?
1
Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325