From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2844 invoked by alias); 23 Nov 2015 16:24:17 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 2790 invoked by uid 89); 23 Nov 2015 16:24:14 -0000 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 Received: from mail-lf0-f48.google.com (HELO mail-lf0-f48.google.com) (209.85.215.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 23 Nov 2015 16:24:12 +0000 Received: by lffu14 with SMTP id u14so111204536lff.1 for ; Mon, 23 Nov 2015 08:24:09 -0800 (PST) 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) Received: by 10.25.80.202 with HTTP; Mon, 23 Nov 2015 08:24:09 -0800 (PST) In-Reply-To: <56532F6A.3020906@cs.umass.edu> References: <56532F6A.3020906@cs.umass.edu> Date: Mon, 23 Nov 2015 16:24:00 -0000 Message-ID: Subject: Re: Awk not ouputting results via echo From: Lester Anderson To: moss@cs.umass.edu, cygwin@cygwin.com Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg00358.txt.bz2 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 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