You can also use let, which may make more senselet "myVar=$myVar+1"As for floating point you need something like bc to handle thatmyVar=5.4myOtherVar=3.1myVar=$(echo "scale=2; ($myVar + 3.14) / $myOtherVar" | bc)
echo $myVarIf ran the above would print 2.75On Mon, Mar 2, 2015 at 7:15 PM, der.hans <PLUGd@lufthans.com> wrote:---------------------------------------------------Am 02. Mär, 2015 schwätzte Michael Havens so:
moin moin Mike,
see the Arithmetic Expansion portion of the bash man page for details.
$((expression))
That says to evaluate the expression and substitute the result. Remember
that the shell only does interger math, no decimals.
:) ~$ echo $(( 4 / 2 ))
2
:) ~$ echo $(( 4 / 3 ))
1
:) ~$ echo $(( 4 * 3 ))
12
:) ~$
Note that you don't need to escape the * when using arithmetic expansion
because the $(( )) is already quoting.
ciao,
der.hans--
just starting with this so please, bear with me....
Anyways I am looking at this beginner's script:
#! /bin/bash
myvar=0
while [ $myvar -ne 20 ]
do
echo $myvar
myvar=$(( $myvar + 1 ))
done
Now my mind can wrap itself around everything in this script except for tis
line:
myvar=$(( $myvar + 1 ))
Where my difficulty arises is why the '$' before the '(('?
(it was geast fun running that script with a minus sign instead!)
:-)~MIKE~(-:
# http://www.LuftHans.com/ http://www.PhxLinux.org/
# "The first requisite of a good citizen in this republic of ours is that
# he should be able and willing to pull his weight." -- Theodore Roosevelt
PLUG-discuss mailing list - PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss
---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss