title: Bash basename syntax
body: <p>I'm trying to write a script that takes the basename of an argument, then checks if there is an extension in that argument. If there is, it prints the extension.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>file=basename $1
  ext=${file%*}
  echo ${file#"$stub"}
  echo $basename $1
  </code></pre>
  
  <p>I'm echoing the final $basename $1 to check what the output of basename is.</p>
  
  <p>Some tests reveal:</p>
  
  <pre><code>testfile.sh one.two
  ./testfile: line 2: one.two: command not found
  one.two
  
  testfile.sh ../tester
  ./testfile: line 2: ../tester: No such file or directory
  ../tester
  </code></pre>
  
  <p>So neither $basename $1 are working. I know it's a syntax error so could someone explain what I'm doing wrong? </p>
  
  <p>EDIT:</p>
  
  <p>I've solved my problem now with:</p>
  
  <pre><code>file=$(basename "$1" )
  stub=${file%.*}
  echo ${file#"$stub"}
  </code></pre>
  
  <p>Which reduces my argument to a basename, thank you all.</p>