Here are some shell statements that should get you started. In your example, replace g with $2.
Code:
$ g="L"
$ typeset -i j
$ j=$g
$ echo $j
0
$ g=2347834
$ j=$g
$ echo $j
2347834
$
Firstly, g has the value of "L" which is clearly not an integer. I then create a new variable - j - using typeset and it will only be able to store integer values. When I assign the value of $g to j, it fails and j has a value of zero.
When $g has a integer value, the assignment to j will work and $g will equal $j.
In your example, replacing $g with $2, you can test that $2 = $j after assigning the value of $2 to j. If $j has the same value as $2, then you know $2 is an integer.