What is the mistake?

#!/bin/bash
if $1=1]; then
#my codes
else if $1=2];
#my codes
fi

Try this instead:

#!/bin/bash

#: Title       : /home/james/bin/test
#: Date Created: Thu Nov 5 10:54:53 CDT 2010
#: Last Edit   : Sat Nov 5 10:54:53 CDT 2010
#: Author      : J. McDaniel
#: Version     : 1.00
#: Description : 
#: Options     : 

if  "$1" == "1" ]; then
  #my codes
else 
  if  "$1" == "2" ]; then
    #my codes
  fi
fi 

exit 0
# End Of Script

Thank You,

  • There should always be spaces before and after “=” in comparaison and no spaces in variable assignements.
  • It should be elif
    in sh and bash on a single line and not else if. If you use “else if” you need a second “fi” (since you have two “if”).
  • the following comparaison is possible too and compares numbers instead of strings:
if  $1 -eq 1 ] ; then

Thank you.I was in misconception that shell interpreter do not recognize spaces

If you are trying to assign the value of a variable, it don’t allow spaces and uses a single =, but your were trying to check if two values are equal then it must use two == or -eq and spaces are OK. Further, you have two if’s and each one requires a fi to end it.

Thank You,