From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47321 invoked by alias); 21 Aug 2017 22:53:58 -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 47305 invoked by uid 89); 21 Aug 2017 22:53:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=Michel, Hx-languages-length:1358, moss, Moss X-HELO: mailsrv.cs.umass.edu Received: from mailsrv.cs.umass.edu (HELO mailsrv.cs.umass.edu) (128.119.240.136) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 21 Aug 2017 22:53:57 +0000 Received: from [128.119.40.245] (csvpn21.cs.umass.edu [128.119.40.245]) by mailsrv.cs.umass.edu (Postfix) with ESMTPSA id D65724050D96; Mon, 21 Aug 2017 18:53:54 -0400 (EDT) Reply-To: moss@cs.umass.edu Subject: Re: alias appears to not work inside a called bash script References: <000001d31acd$108b0340$31a109c0$@rogers.com> To: cygwin@cygwin.com From: Eliot Moss Message-ID: <071eb206-e739-ae88-a650-055c99cae046@cs.umass.edu> Date: Mon, 21 Aug 2017 22:53:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <000001d31acd$108b0340$31a109c0$@rogers.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00189.txt.bz2 On 8/21/2017 6:30 PM, Michel LaBarre wrote: > Hello all, > > I have a 4 line bash script: > #!/bin/bash > alias nawk=gawk > alias nawk > nawk 'BEGIN {FS="^"} ; (length($0) > maxline) { maxline = length($0) ; > line=$0} ; END{print maxline, line}' $* > > > When I run the script I see: > alias nawk='gawk' > /cygdrive/c/mybin/maxline/: line 4: nawk: command not found > > It looks like the alias is properly defined but it does not appear to take > effect. > > Same thing happens if I alias to awk instead of qawk. > > Same thing happens if I define the alias in .bashrc (I include an echo in > bashrc to confirm that it is being invoked). > > My .bashrc is not likely a factor - I empty it and the result is the same. > No carriage returns in the script or .bashrc. > > I have updated everything August 5th using setup and letting all "Pending" > pkgs update so I believe I am up to date. > > The funny thing is that it works ok from an interactive session, whether the > alias is explicitly defined in the session or in .bashrc. From the bash man page: "Aliases are ot expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below)." Could that be the root of your difficulty? 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