problem passing arguments to script

Hi,
I am writing a script, which is invoked from other system using ssh.
I have problems reading the arguments passing to the script. If the argument has a space in it (ex "rev 2.00"), the script considers "rev" as 1 argument and "2.00" as another. Instead i want "rev 2.00" to be considered as a single argument.

Below is my script and sample output.


#myscript.sh

#! /bin/bash
     script=${0##*/}
     value1=$1
     value2=$2
     value3=$3

     echo "received parameters :"
     echo "script: $script, value1: $value1, value2: $value2 value3: $value3"

Output:
bash-3.00$ ssh root@192.168.10.121 /usr/local/sbin/myscript "Rev_1" "Rev 2" "Rev3"
root@192.168.10.121's password:
received parameters :
script: myscript, value1: Rev_1, value2: Rev value3: 2

desired output:
script: myscript, value1: Rev_1, value2: Rev 2, value3: Rev3

Try putting quotes around it because of the whitespace.

$ cat myscript.sh
#! /bin/bash
     script=${0##*/}
     value1="$1"
     value2="$2"
     value3="$3"

     echo "received parameters :"
     echo "script: $script, value1: $value1, value2: $value2 value3: $value3"

$ ./myscript.sh "Rev_1" "Rev 2" "Rev3"
received parameters :
script: myscript.sh, value1: Rev_1, value2: Rev 2 value3: Rev3

That did not help.. I am getting same output as before, even after your modification. To add, I am using bash shell, hope it is not shell dependent

Try using the getopts command as described in this thread

This will allow you to specify an argument per switch and you will not have to worry about which field is in which variable.

It is very foolish to experiment with scripts using the root account. Execute as a regular user until the script is working properly, and even then only use root if really need root privileges.

$ ssh 192.168.0.101 "bin/try x 'y z' z"
chris@192.168.0.101's password: 
received parameters :
script: try, value1: x, value2: y z value3: z

Or:

ssh 192.168.0.101 'bin/try x "y z" z'

Thanks Cris...It's working as desired..:b:
Thank's for the suggestion for not experimenting things as root..