Re: Recomended tutoial(s) on doing arithmetic in Bash scripts
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sun, Mar 05, 2017 at 12:10:43PM -0600, Richard Owlett wrote:
[...]
> How about the whole app <grin>
> You solved my problem with one line.
Glad it helped :)
[...]
> I needed to report the number of bytes downloaded for each portion
> of a project [...]
Let me pick a nit...
> mystring=$(echo $(grep "usb0" /proc/net/dev))
This should be equivalent to
mystring=$(grep "usb0" /proc/net/dev)
(background:
- grep "usb0"/proc/net/dev
spits out the line(s) containing the pattern "usb0"
- the $(...) around it expands it in the shell inline
- the echo spits that again out to stdout
- the $(...) around it expands it again in-line
So unless the expansion is doing anything funky (which we won't hope,
but see below), you can unwrap the outer $(echo ...).
Now the second nit: I'm not sure whether there's a case when the
unquoted $(...) might undergo a further expansion by the shell,
so it's prudent to quote it, like so:
mystring="$(grep "usb0" /proc/net/dev)"
(I know, my example wasn't... exemplar in this respect, but I knew
I was only getting plain numbers and I was kind of lazy: bad tomás)
> Someone on another group wanted me to use LibreOffice Calc ;/
Might work, but don't ask me how :-/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAli8c80ACgkQBcgs9XrR2kb3cwCfTzWmOlditJ0hK9vGMkpeJZQY
2BEAmwdhRnREpwGMQ9k8I1uS4jL10D9E
=+2Ss
-----END PGP SIGNATURE-----
Reply to: