title: Echo the basename in shell
body: <p>I have a path to the directory and I need to extract the filename out of it so that I can use further in the shell script.</p>
  
  <pre><code>#!/bin/sh
  dir=/var/tmp/file1
  fname= basename $dir 
  echo $fname
  echo "The script executes:" $fname 
  echo $fname
  </code></pre>
  
  <p>Here the fname gets printed only once. In all other cases, it comes as blank.</p>
  
  <p>Where is it that I am going wrong?</p>