Help parsing command line arguments in bash

Looking for a little help parsing some command line arguments in a bash script I am working on, this is probably fairly basic to most, but I do not have much experience with it.

At the command line, when the script is run, I need to make sure the argument passed is a file, it exists in the current directory, and that there is only one argument.

Here is the code I am using for this task now, but it does not produce the result I need:

if [ -f $1 -a $# -eq 1 ] 

Thanks!

what is the message your are getting?
Have you echo'ed the values before the "if" ?

Posix-sh, ksh, bash, ...

[  $#  -lt 1 ]  &&  echo "need arg" && exit 1
[ ! -f  "$1" ]   &&  echo "file $1 must exist"  && exit 1

Your version [ -f $1 -a $# -eq 1 ] give error if you don't give any arguments, because $1 is empty, but if you put -f "$1" then value is some string, maybe very short (len 0).
Why ? Read full story

!/bin/bash -x

returns:

+ '[' -f filename -a 1 -eq 1 ']'
++ cut -d: -f3
++ sort -r
++ head -n1

---------- Post updated at 06:00 PM ---------- Previous update was at 05:08 PM ----------

ahhhh, thanks guys, I figured it out, problem was elsewhere.