Also removing the quotes from yours and using the ]] tests I was able
to get this to work:
<code interpreter="/bin/bash">
export BIG_NUM=123456k
if $BIG_NUM =~ ([0-9]+) ]] ; then echo $? $BASH_REMATCH worked; else
echo $? $BASH_REMATCH failed; fi
</code>
Good luck.
eeijlar wrote:
> Hi,
>
> I understand that since Bash 3.0, there is a regular expression
> operator available in bash. I want to extract the digits from this
> string:
>
>
> Code:
> --------------------
> total 578998k
> --------------------
>
>
> The string is assigned to a variable in bash, MEM_TOTAL. So I was
> trying this:
>
>
> Code:
> --------------------
> “$MEM_TOTAL” =~ “[0-9]*”
> --------------------
>
>
> The result is supposed to go into a special bash variable,
> $BASH_REMATCH.
>
> I have been rooting at it for hours, to no avail. Any ideas greatly
> appreciated.
>
> /jlar
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
This is a cavil but, export is only needed if you intend the variable to be seen by child processes. For local use within the shell process, you can just set the value with
BIG_NUM=123456k.
Yes, very true, but I export just for kicks anyway since it works like
‘set’ (at least on Linux) and half the time I do want values in child
processes. Good point all around.
Good luck.
ken yap wrote:
> This is a cavil but, export is only needed if you intend the variable to
> be seen by child processes. For local use within the shell process, you
> can just set the value with
> BIG_NUM=123456k.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/