-----BEGIN PGP SIGNED MESSAGE-----
>>>>> "Gordon" == Gordon <[EMAIL PROTECTED]> writes:
Gordon> I've searched all over for an answer to this and haven't
Gordon> found one yet! Is there a way in a bash script to test if
Gordon> a variable contains an integer? I want to create a script
Gordon> that uses some simple arithmetic but bash bombs out if you
Gordon> try to do a comparison or arithmetic with a non-numeric
Gordon> value. Basically, something like:
Depends on how you want to treat invalid values. If you can treat
them as zero, you can get away with:
read var
X=$((var+0))
<do something>
If you have to catch them, you do something like
read var
X=${var//[0-9]*/}
if [ -n "$X" ]; then
<complain about invalid value>
else
<do something>
fi
NB: the above treats negative numbers as invalid which may not be
acceptable for you application....
roland
- --
PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD RL Enterprises
[EMAIL PROTECTED] 6818 Madeline Court
[EMAIL PROTECTED] Brooklyn, NY 11220
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv
Comment: Processed by Mailcrypt 3.5.4, an Emacs/PGP interface
iQCVAwUBPkkk4uoW38lmvDvNAQHDPQP+IL8sNYmahKAdiQVH3OUqq/rjhtZSzU0Z
x9vYN9ydfdbkME1tMccpb7QCsP4uzuxNGB8wc0aDGEVlDSCka80hDqjMZCaZW6Tl
PSr2+8K2t9uv9+t51IqJkzsUc0+RBCp0DV8LEeCnX5GyVVsnKG94Rpw3VaH1tBum
djeOYZRjzBU=
=yE1a
-----END PGP SIGNATURE-----
--
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list