www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2017/08/22/14:25:32

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:from:date
:message-id:subject:to:content-type; q=dns; s=default; b=jhAMQ7B
L8WIkiQJbRl1OqeXPi+sjpbu/xvzSnXRIT9mvNoN7+n1jv2UI2K4Swmc36CNIleY
IE3Q6ZXajGlQeCcSKpLuxzSwoZULVBFwjKXI9w9MQe2AMNtjIjZ1t7hDa0LxA+pq
fufBu5qTyMYOo+5D2z74fCb8e9I7Tmsyk5Es=
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:from:date
:message-id:subject:to:content-type; s=default; bh=0roz/OaqxZ2x+
hWQZFCndJO+JJ4=; b=IRxiLIEAyFNDuad86+cUq6fFo9DHUGeyauBIIgx4jbu8y
Y/GYZ20e6ys7oJ/1TPQG6DK8icWOYhH8kqSos7OKllldHNsXdxZfSz4B7QoYHqEr
1cTqHFhz7Ry/Ysj0DQ7zStoicwMia+vrGunzEpa3aTWSIeU37sUdsKODfq7Fgc=
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.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=world!, world
X-HELO: mail-qk0-f176.google.com
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=dRagE4vMRjD0HpMjDuwdCMDvHyvG8TX6DnSh5MENOYQ=; b=lch+s9qIS3QSi+AknB7G6lKo/U5hYPPSHXSdrKqo8JTiW+M0jpRze+3J6BDH6kUXBw TteT6xt9BOZs6wZ4O5h2H5c7cl6MFaKlv7CKmm1e66KMi5xptCv7D4kitXQZk7hTxVo+ SqfiM1u6bQwFei8D7rIHs+NrcNpLQFcVGo/VOk7qz6nHLo49y0cYejaFIH4pDgvykztA 3+/BJFH6wQN3HBJfvQTJpXv4vjHC3ATm8AfoE9WqWxZAY6kWGZfMaToxHGpa+Zh5cL13 ceMOhHJLsWSuYWO1cJLtM8HumiER63rNNtCvlSMm/Chw5hPEkiwV7gwsJBG8mU9l5/dF 8sgg==
X-Gm-Message-State: AHYfb5gLi8iHETGtGrCwguzmxFTOzQCRpRUqOvM+GYk14+6SY0jpd3Bg Qby+0tzInRATWQLeD30AXjfIOyPJmw==
X-Received: by 10.55.147.199 with SMTP id v190mr104007qkd.230.1503426313713; Tue, 22 Aug 2017 11:25:13 -0700 (PDT)
MIME-Version: 1.0
In-Reply-To: <637017a5-b774-cb10-f064-065d20e421b3@cs.umass.edu>
References: <000001d31acd$108b0340$31a109c0$@rogers.com> <CANnLRdgWnygyp36uYmpzq7i3BvgHonL5H8CPy_Vr+wOYmWjp4w AT mail DOT gmail DOT com> <0ac245f1-002b-2993-c1de-e4ddaafa9c7d AT cs DOT umass DOT edu> <CANnLRdgBU-Gact9rTN3cSYVy6UMe83r=EYyVsvwS97k8VuxD6g AT mail DOT gmail DOT com> <637017a5-b774-cb10-f064-065d20e421b3 AT cs DOT umass DOT edu>
From: Stephen John Smoogen <smooge AT gmail DOT com>
Date: Tue, 22 Aug 2017 14:25:13 -0400
Message-ID: <CANnLRdihpyMjU6NyoFMmxiN3SJ22fAYZVprZknoW+JH1uJUi1w@mail.gmail.com>
Subject: Re: alias appears to not work inside a called bash script
To: moss AT cs DOT umass DOT edu, cygwin AT cygwin DOT com
X-IsSubscribed: yes

On 22 August 2017 at 12:45, Eliot Moss <moss AT cs DOT umass DOT edu> wrote:
> On 8/22/2017 11:18 AM, Stephen John Smoogen wrote:
>>
>> On 22 August 2017 at 10:47, Eliot Moss <moss AT cs DOT umass DOT edu> wrote:
>>>
>>> On 8/22/2017 10:31 AM, Stephen John Smoogen wrote:
>
>
>>> It's a *bash* default - it has nothing to do with Cygwin as distinct
>>> from other bash installations.  If you had a different experience
>>> elsewhere, it could be that the default was overridden in some system
>>> wide bashrc file - but that strikes me as unlikely.  I suspect that
>>> this is done as a security measure, to prevent an alias from introducing
>>> a surprise.
>>>
>>
>> I checked on CentOS and there is no shopt option set in any of the
>> /etc/ files. It must be a compiled in default of some sort as EL6 and
>> EL7 both work without an explicit `shopt -s expand_aliases`. I then
>> tried on an Ubuntu 16.04 system and it works without the `shopt -s
>> expand_aliases` also.
>>
>> I didn't have access to anything else at the moment so I can't say
>> which other systems might actually follow the default other than
>> Cygwin at the moment.
>
>
> Hmmm ... One of my servers runs EL7 and it works there exactly as under
> Cygwin on my laptop.  I wonder: Is there an nawk installed somewhere
> on your path on these CentOS and EL* systems?  Put another way, if you
> put 'type -a nawk' in your script *before* the alias lines, what output
> do you get?  And what about shopt?  I added these lines before the alias
> lines:
>
> shopt | grep expand_aliases
> type -a nawk
> type -t nawk
>
> Regards - Eliot
>
>
> --
> 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
>

OK I figured it out. I didn't copy the original script correctly.

[ssmoogen AT el-7 ~]$ ./x.sh foobar
Before alias
expand_aliases on
./x.sh: line 4: type: nawk: not found
After alias
expand_aliases on
nawk is aliased to `/usr/bin/awk'
alias
Hello World!
[ssmoogen AT el-7 ~]$ cat x.sh
#!/bin/sh
echo "Before alias"
shopt | grep expand_aliases
type -a nawk
type -t nawk
alias nawk='/usr/bin/awk'
echo "After alias"
shopt | grep expand_aliases
type -a nawk
type -t nawk
nawk '{print $0}' $*

Change that #!/bin/sh to #!/bin/bash

[ssmoogen AT el-7 ~]$ ./x.sh foobar
Before alias
expand_aliases off
./x.sh: line 4: type: nawk: not found
After alias
expand_aliases off
./x.sh: line 9: type: nawk: not found
./x.sh: line 11: nawk: command not found

So when you use bourne sh compatibility aliases get expanded. When you
don't.. they do as the reporter says.

-- 
Stephen J Smoogen.

--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019