| delorie.com/archives/browse.cgi | search | 
| X-Recipient: | archive-cygwin AT delorie DOT com | 
| DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id | 
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:mime-version:in-reply-to:references:date | |
| :message-id:subject:from:to:content-type; q=dns; s=default; b=l2 | |
| Rxp8YgUsDXM/KBzlOn5tf7W8aLADPAWfIro8UXyRhjROw9HRNOAlZeIl0JWI+y3d | |
| AaH4Cif4zpTbFsohr6EVxgHVlmeuvrYcJFH5i75KBVDTeUq7iddhHZsOWrPVBRni | |
| uPAlYzdxh5exRB7tlk58XFQcCG1TTdtzLcH/rIVBw= | |
| DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id | 
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:mime-version:in-reply-to:references:date | |
| :message-id:subject:from:to:content-type; s=default; bh=dpEQhj+Z | |
| gTqrpbM7cXyP82Mayd4=; b=RfZzlAetrYfRATwCMxr+lrW4d7Fsz6NuDnPT6MXf | |
| 8ZvgX4We4OO/NLAuXMVK+uFoHFdvu27fXtSO8+6JqoEX6mSdNTfLYv8KBELXjxj5 | |
| tOdAYVdf3MsIbQ/IbY7Joy3JwL/lyxprmpPqz7f/B1Sy/bU9l3puWezRWhgD0Urz | |
| YQQ= | |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm | 
| List-Id: | <cygwin.cygwin.com> | 
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> | 
| List-Archive: | <http://sourceware.org/ml/cygwin/> | 
| List-Post: | <mailto:cygwin AT cygwin DOT com> | 
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> | 
| Sender: | cygwin-owner AT cygwin DOT com | 
| Mail-Followup-To: | cygwin AT cygwin DOT com | 
| Delivered-To: | mailing list cygwin AT cygwin DOT com | 
| Authentication-Results: | sourceware.org; auth=none | 
| X-Virus-Found: | No | 
| X-Spam-SWARE-Status: | No, score=1.2 required=5.0 tests=AWL,BAYES_20,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 | 
| X-HELO: | mail-lf0-f48.google.com | 
| MIME-Version: | 1.0 | 
| X-Received: | by 10.25.90.195 with SMTP id o186mr11396624lfb.9.1448295849099; Mon, 23 Nov 2015 08:24:09 -0800 (PST) | 
| In-Reply-To: | <56532F6A.3020906@cs.umass.edu> | 
| References: | <CAE3taFC=tjki1FTfbjyt+KnEGsWmrj63FMeBjgRswRwRSKdAWQ AT mail DOT gmail DOT com> <56532F6A DOT 3020906 AT cs DOT umass DOT edu> | 
| Date: | Mon, 23 Nov 2015 16:24:09 +0000 | 
| Message-ID: | <CAE3taFDt50FGGCdQNnH5P84RCFt7t4j1SqyTTkVsbHf0XhVBDg@mail.gmail.com> | 
| Subject: | Re: Awk not ouputting results via echo | 
| From: | Lester Anderson <arctica1963 AT gmail DOT com> | 
| To: | moss AT cs DOT umass DOT edu, cygwin AT cygwin DOT com | 
| X-IsSubscribed: | yes | 
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 AT cs DOT umass DOT 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
| webmaster | delorie software privacy | 
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |