Assalam-o-alaikum,
I am making a shell script in which i need user to input a Signed 16bit Integer as arguments to the script.
The script will take 6 arguments which all should be Signed 16bit integer.
I would like to know how can i verify that the value that user has input is a Signed 16bit integer. I need to verify $1 $2 $3 $4 $5 $6.
Looking for a positive and quick reply.
Validate User Input is 16bit signed integer
Validate User Input is 16bit signed integer
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
-
- Site Admin
- Posts: 5132
- Joined: Fri May 02, 2003 10:24 am
- Location: Karachi
- Contact:
Re:
Dear mudasir,
Hello,
You can use something like this ...
Best Regards.
Hello,
You can use something like this ...
Code: Select all
if [ $# -ne 16 ]
then
echo 1>&2 Usage: $0
exit 127
fi
Farrukh Ahmed
just check if each number is between -32768 and 32767.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Assalam-o-alaikum,
Thanks allot for the help, i have completed the user input validation function. Now i am stuck in another mathematical error. Please help me out in this.
my script takes 6 parameters as input
./<script name> X1 Y1 Z1 X2 Y2 Z3
then script perform some calculation on these values, where i am stuck is that, if Y1 value or any other value has a "-" sign with it, shell gives me an error
DIV=`expr $Y2 - $Y1`
T=`expr -$Y1 / $DIV` &> /dev/null
this is where i get an error, error is
"expr: non-numeric argument"
when script run in debug mode i see
++ expr 2 - -2
+ DIV=4
++ expr --2 / 4
the double "--" sign is creating problem.
The formula through which i have to do calculation has a "-" sign so how to overcome this issue.
Thanks in advance.
Thanks allot for the help, i have completed the user input validation function. Now i am stuck in another mathematical error. Please help me out in this.
my script takes 6 parameters as input
./<script name> X1 Y1 Z1 X2 Y2 Z3
then script perform some calculation on these values, where i am stuck is that, if Y1 value or any other value has a "-" sign with it, shell gives me an error
DIV=`expr $Y2 - $Y1`
T=`expr -$Y1 / $DIV` &> /dev/null
this is where i get an error, error is
"expr: non-numeric argument"
when script run in debug mode i see
++ expr 2 - -2
+ DIV=4
++ expr --2 / 4
the double "--" sign is creating problem.
The formula through which i have to do calculation has a "-" sign so how to overcome this issue.
Thanks in advance.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
why don't you explain the mathematics behind the calculation? what does it mean for y1 to be negative in the mathematical equation?
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
you are trying to minus a negative integer from another integer and then divide it by another integer?
if so then use the + operator for subtraction operation too, it will give you the right answer.
if so then use the + operator for subtraction operation too, it will give you the right answer.
Azfar Hashmi
Email : azfarhashmi@hotmail.com
Email : azfarhashmi@hotmail.com