Hi
I want to find whether the argument passed to my script ends in a number or not. Like, I want to find out if the argument is of the form: xyzwpq123 or just of the form xyzwpq.
Can someone please help me!?
Thanks
Hi
I want to find whether the argument passed to my script ends in a number or not. Like, I want to find out if the argument is of the form: xyzwpq123 or just of the form xyzwpq.
Can someone please help me!?
Thanks
To check if the argument ends with a number
i=`echo $1 | grep -c "[0-9]$"`
if i = 1 then the argument ends with a number, else if i = 0 then the argument doesn't end with a number
Your question was somewhat vague. Are you looking to check for the specific pattern provided or simply if the variable end in one or numerals.
If the latter, the following is one way of performing such a test in ksh93
#!/bin/ksh93
var=xyzwpq123
# print ${var/%[0-9]*/""}
if [[ ${var/%[0-9]*/""} != $var ]]
then
print "Contains trailing numerals"
else
print "Contains no trailing numerals"
fi