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
  • 62
  • 391
  • 407
chuacw
  • 1,685
  • 1
  • 23
  • 35

2 Answers2

2

One way to do it

if [[ $FILENAME_VAR =~ Feature ]]
then
  echo good
else
  echo bad
fi
Zombo
  • 1
  • 62
  • 391
  • 407
  • 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
  • 776,304
  • 153
  • 1,341
  • 1,358