checking for hexadecimal vals only in a string in bash
inode0
inode0 at gmail.com
Fri Sep 19 13:56:28 UTC 2014
On Thu, Sep 18, 2014 at 4:31 PM, Chris Kottaridis
<chriskot at quietwind.net> wrote:
> In a bash shell script I want to see if a string has nothing but hexadecimal
> values in it.
>
> So:
>
> A098FE or af098fe
>
> should be true
>
> hello
>
> should not.
>
> How do I check for that ?
>
> I've been playing with
>
> if [[ $val =~ '/^[A-Fa-f0-9]+$/' ]] ; then
> echo is hex
> else
> echo is not hex
> fi
>
> I've tried various incantations of above and also tried using grep but
> can't seem to get it just right.
>
> Any help appreciated.
Chris,
Looks like you are really close.
if [[ $val =~ ^[A-Fa-f0-9]+$ ]] ; then
John
More information about the users
mailing list