title: Bash if filename exists
body: <p>I have a script that I call from another script with a specific filename as second argument. </p>
  
  <pre><code>script1 &lt;/var/tmp/outputfile&gt;
  </code></pre>
  
  <p>within script1, I want to add a logic to find if the filename after /var/tmp is 'outputfile' if, yes I need to add some logic, if not other logic. </p>
  
  <p>Following code is not working in the script1.sh.</p>
  
  <pre><code>#!/bin/sh
  
  if [ $# -ne 1 ]; then
      echo "Invalid usage"
      echo "Usage: $0 &lt;logfile&gt;"
      exit 1
  fi
  
  
  if [[ $1 == *"outputfile" ]]; then        
      echo "Found it"
  else    
      echo "Search fail"
  fi
  </code></pre>
  
  <p>Note that input always includes the full path where the file is generated. I just need to search for the filename that is at the end of the input string ($1). I tried many ways. It is not working in the script. </p>
  
  <p>If I try similar logic directly in the shell it is working fine. Can someone tell me what should I add in the script. </p>
  
  <pre><code>[root@mgmt:~]$echo $file
  /var/tmp/output
  [root@mgmt:~]$if [[ $file == *"output" ]] ; then echo "ok";  else echo "fail";fi
  ok
  </code></pre>