BASH scripting

Michael Havens bmike1 at gmail.com
Mon Mar 2 19:30:15 MST 2015


Thank you


:-)~MIKE~(-:

On Mon, Mar 2, 2015 at 7:27 PM, Bryan O'Neal <
Bryan.ONeal at theonealandassociates.com> wrote:

> You can also use let, which may make more sense
>      let "myVar=$myVar+1"
>  As for floating point you need something like bc to handle that
>      myVar=5.4
>      myOtherVar=3.1
>      myVar=$(echo "scale=2; ($myVar + 3.14) / $myOtherVar" | bc)
>      echo $myVar
> If ran the above would print 2.75
>
> On Mon, Mar 2, 2015 at 7:15 PM, der.hans <PLUGd at 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 at 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 at lists.phxlinux.org
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.phxlinux.org/mailman/listinfo/plug-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.phxlinux.org/pipermail/plug-discuss/attachments/20150302/6d3f096e/attachment.html>


More information about the PLUG-discuss mailing list