shell scripting

i made this script

zoo.sh:

#!/bin/bash    
filename=~/.animals 
echo -n "Enter an animal name: "    
read name    
is_in_file=`grep $name $filename`  
if [ -n "$is_in_file" ]; then 
  echo $is_in_file | cut -d= -f2    
else  
  echo -n "Give me description for $name: " 
  read description 
  echo " $name=$description" >> $filename    
fi

is there a way i can make it work different?

i don't want my script to ask for the name. Name should be passed as the first command line argument to the script and description as the second argument

./zoo.sh animal Description

i am learning unix on my own and the book i am using does not make it clear.
any help will be appreciated.

Commandline parameters are $1, $2, and so forth. Substitute these for your $name and $description variables.

That's to say, something like:

#!/bin/bash
if [ $# -ne 2 ]; then
  echo "Usage:  $0 Animal Description"
  exit
fi

filename=~/.animals 
is_in_file=`grep "$1" $filename`  
if [ -n "$is_in_file" ]; then 
  echo $is_in_file | cut -d= -f2    
else  
  echo " $name=$2" >> $filename    
fi

i.e. If the command-line arguments contain spaces, you should quote them.

i.e.

./zoo.sh "snow leopard" "beautiful but wouldn't like to cross one"
#!/bin/bash    
filename=~/.animals $1 $2   
is_in_file=`grep $name $filename`  
if [ -n "$is_in_file" ]; then 
echo $is_in_file | cut -d= -f2    
else  
echo " $1=$2" >> $filename    

not working

Your script is

#!/bin/bash
if [ $# -ne 2 ]; then
  echo "Usage:  $0 Animal Description"
  exit
fi

filename=~/.animals 
is_in_file=`grep "$1" $filename`  
if [ -n "$is_in_file" ]; then 
  echo $is_in_file | cut -d= -f2    
else  
  echo " $name=$2" >> $filename    
fi

$1, $2, etc. are used when calling the script:

./zoo.sh animal Description

They have nothing to do with your input file

filename=~/.animals

What you seem to be trying to do is update the input file with a new description for the given animal?

I would suggest you change the format of your input file (.animals)

$ cat ~/.animals
cat|hates the dog
dog|ate the cat
$ cat zoo.sh
#!/bin/bash
if [ $# -ne 2 ]; then
  echo "Usage:  $0 Animal Description"
  exit
fi

filename=~/.animals
awk -F"|" -v animal="$1" -v description="$2" '$1 == animal { $2 = description } 1' $filename > $filename.new
mv $filename.new $filename