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=IJ | |
1MC/QbijNvtp4ZNjhti2ZkhgcsEB+kVNbXpT3AeSwAaf3Nbp5G21Jzylm9LFY2T5 | |
7q0SUnBJpIGAZWMmL/XOxZyZU05GV0sv7CuMwfYX/V8vrEbZdUqYz0AGP9fiLpJm | |
896nki4czfouKP2gjL5pyh79uJRUSjIpYAdbQudcA= | |
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=PYWcgnZQ | |
ddmDCBgQudLSJ8qgx1Q=; b=MIIV6GJDO2MNOna+vC5OY4NJ2DbtRyxGT6vRZnm3 | |
wzlegewdE80hePeI+8jkh8bkjX76+ejYDfgO3PrPRdOWzsds/GS0Bs9fF+zXXDLG | |
VwQVlsouUzbcu3hD35PXvoCUFCIo2GAHDdeB2Cd1L9qGJaJxhgoB8Dlq1t4IvFyw | |
QTE= | |
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=0.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 |
X-HELO: | mail-lf0-f43.google.com |
MIME-Version: | 1.0 |
X-Received: | by 10.25.161.211 with SMTP id k202mr11934829lfe.161.1448297056450; Mon, 23 Nov 2015 08:44:16 -0800 (PST) |
In-Reply-To: | <CAE3taFDt50FGGCdQNnH5P84RCFt7t4j1SqyTTkVsbHf0XhVBDg@mail.gmail.com> |
References: | <CAE3taFC=tjki1FTfbjyt+KnEGsWmrj63FMeBjgRswRwRSKdAWQ AT mail DOT gmail DOT com> <56532F6A DOT 3020906 AT cs DOT umass DOT edu> <CAE3taFDt50FGGCdQNnH5P84RCFt7t4j1SqyTTkVsbHf0XhVBDg AT mail DOT gmail DOT com> |
Date: | Mon, 23 Nov 2015 16:44:16 +0000 |
Message-ID: | <CAE3taFA3aRZVTu14tug_TcQL7sD9ok12jGWRw6ZQ_hsZ6ufOnw@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 |
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 AT gmail DOT 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 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 |