title: Bash - check for a string in file path
body: <p>How can I check for a string in a file path in bash? I am trying:</p>
  
  <pre><code>if [[$(echo "${filePathVar}" | sed 's#//#:#g#') == *"File.java"* ]]
  </code></pre>
  
  <p>to replace all forward slashes with a colon (:) in the path. It's not working. Bash is seeing the file path string as a file path and throws the error "No such file or directory". The intention is for it to see the file path as a string.</p>
  
  <p>Example: filePathVar could be</p>
  
  <blockquote>
    <p>**/myloc/src/File.java</p>
  </blockquote>
  
  <p>in which case the check should return true.</p>
  
  <p><em>Please note that I am writing this script inside a Jenkins job as a build step.</em></p>
  
  <p><code>Updates as of 12/15/15</code></p>
  
  <p>The following returns <code>Not found</code>, which is wrong.</p>
  
  <pre><code>#!/bin/bash
  sources="**/src/TESTS/A.java **/src/TESTS/B.java"
  
  if [[ "${sources}" = ~B.java[^/]*$ ]];
  then
  echo "Found!!"
  else
  echo "Not Found!!"
  fi
  </code></pre>
  
  <p>The following returns <code>Found</code> which also also wrong (removed the space around the comparator <code>=</code>).</p>
  
  <pre><code>#!/bin/bash
  sources="**/src/TESTS/A.java **/src/TESTS/C.java"
  
  if [[ "${sources}"=~B.java[^/]*$ ]];
  then
  echo "Found!!"
  else
  echo "Not Found!!"
  fi
  </code></pre>
  
  <p>The comparison operation is clearly not working.</p>