public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Lester Anderson <arctica1963@gmail.com>
To: moss@cs.umass.edu, cygwin@cygwin.com
Subject: Re: Awk not ouputting results via echo
Date: Mon, 23 Nov 2015 16:44:00 -0000	[thread overview]
Message-ID: <CAE3taFA3aRZVTu14tug_TcQL7sD9ok12jGWRw6ZQ_hsZ6ufOnw@mail.gmail.com> (raw)
In-Reply-To: <CAE3taFDt50FGGCdQNnH5P84RCFt7t4j1SqyTTkVsbHf0XhVBDg@mail.gmail.com>

As  a test I did a simple function to read the inputs:

#!/bin/sh
lon_min=-12
lon_max=0
lat_min=28
lat_max=39
R_d=167
R_i=20
function Test() {
    echo Test function: $lon_min $lon_max $lat_min $lat_max $R_d $R_i
    }
#
Test > test.txt
# test.txt -> -12 0 28 39 167 20

Still needs awk to do those fiddly bits!

Lester

On 23 November 2015 at 16:24, Lester Anderson <arctica1963@gmail.com> wrote:
> Hi Eliot,
>
> I can see the logic of the function, but not sure how it is
> implemented from the section I have:
>
> lon_min=-12
> lon_max=0
> lat_min=28
> lat_max=39
> R_d=167
> R_i=20
>
> echo $lon_min $lon_max $lat_min $lat_max $R_d $R_i |
> awk "{R_t=6370;
>       pi=3.14159;
>       lat_av=(($lat_max+$lat_min)/2)*(pi/180.);
>       lon_av=(($lon_min+$lon_max)/2);
>       d_lat_e=($R_d/R_t)*180./pi;
>       d_lon_e=($R_d/(R_t*cos(lat_av)))*180./pi;
>       d_lat_i=($R_i/R_t)*180./pi;
>       d_lon_i=($R_i/(R_t*cos(lat_av)))*180./pi;
>       lon_e_min=$lon_min-d_lon_e;
>       lon_e_max=$lon_max+d_lon_e;
>       lat_e_min=$lat_min-d_lat_e;
>       lat_e_max=$lat_max+d_lat_e;
>       lon_i_min=$lon_min-d_lon_i;
>       lon_i_max=$lon_max+d_lon_i;
>       lat_i_min=$lat_min-d_lat_i;
>       lat_i_max=$lat_max+d_lat_i;
>       print lon_e_min,lon_e_max,lat_e_min,lat_e_max,lon_i_min,lon_i_max,lat_i_min,lat_i_max,lat_av*180./pi,lon_av;
> }" | read lon_e_min lon_e_max lat_e_min lat_e_max lon_i_min lon_i_max
> echo $lon_e_min $lon_e_max $lat_e_min $lat_e_max $lon_i_min $lon_i_max
> $lat_i_min $lat_i_max $lat_av $lon_av
>
> Do you have an example function that shows the workflow? Sorry not an
> awk/cygwin expert!
>
> Thanks
> Lester
>
> On 23 November 2015 at 15:23, Eliot Moss <moss@cs.umass.edu> wrote:
>> Ok, I think I have a sense of an underlying problem here.
>>
>> When you do:  ... | read v1 v2 ...
>>
>> The read executes in an inferior process, setting variables there.
>> The process then exits and you have no bindings in the parent shell,
>> which is where you want them.
>>
>> Maybe something like this would suit you better:
>>
>> myfunction() {
>>   ... stuff using positional arguments $1, $2, etc.
>> }
>>
>> myfunction $(awk blah ...)
>>
>> This take the output of the invocation of awk and puts it
>> where $(awk ...) was, which will invoke myfunction with
>> the line, parsing it into separate arguments (I believe).
>>
>> You could also capture the line using something like this:
>>
>> line="$(awk ...)"
>>
>> and then you can fiddle the result however you want, but I think that
>> calling a function (or another script) is probably simpler here.
>>
>> Regards -- Eliot Moss
>>
>>
>> --
>> Problem reports:       http://cygwin.com/problems.html
>> FAQ:                   http://cygwin.com/faq/
>> Documentation:         http://cygwin.com/docs.html
>> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2015-11-23 16:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-23 13:17 Lester Anderson
2015-11-23 14:00 ` Lester Anderson
     [not found]   ` <5653288B.5040004@cs.umass.edu>
2015-11-23 15:11     ` Lester Anderson
2015-11-24 18:32       ` cyg Simple
2015-11-23 14:42 ` cyg Simple
2015-11-23 15:23 ` Eliot Moss
2015-11-23 16:24   ` Lester Anderson
2015-11-23 16:44     ` Lester Anderson [this message]
2015-11-23 16:53     ` Eliot Moss
2015-11-23 20:41 ` Lee
2015-11-24 10:54   ` Lester Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAE3taFA3aRZVTu14tug_TcQL7sD9ok12jGWRw6ZQ_hsZ6ufOnw@mail.gmail.com \
    --to=arctica1963@gmail.com \
    --cc=cygwin@cygwin.com \
    --cc=moss@cs.umass.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).