From: Stephen John Smoogen <smooge@gmail.com>
To: moss@cs.umass.edu, cygwin@cygwin.com
Subject: Re: alias appears to not work inside a called bash script
Date: Tue, 22 Aug 2017 18:25:00 -0000 [thread overview]
Message-ID: <CANnLRdihpyMjU6NyoFMmxiN3SJ22fAYZVprZknoW+JH1uJUi1w@mail.gmail.com> (raw)
In-Reply-To: <637017a5-b774-cb10-f064-065d20e421b3@cs.umass.edu>
On 22 August 2017 at 12:45, Eliot Moss <moss@cs.umass.edu> wrote:
> On 8/22/2017 11:18 AM, Stephen John Smoogen wrote:
>>
>> On 22 August 2017 at 10:47, Eliot Moss <moss@cs.umass.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@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@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@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
next prev parent reply other threads:[~2017-08-22 18:25 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-21 22:30 Michel LaBarre
2017-08-21 22:53 ` Eliot Moss
2017-08-21 22:55 ` alias appears to not work inside a called bash scripty Duncan Roe
2017-08-22 1:01 ` Michel LaBarre
2017-08-22 14:31 ` alias appears to not work inside a called bash script Stephen John Smoogen
2017-08-22 14:47 ` Eliot Moss
2017-08-22 15:19 ` Stephen John Smoogen
2017-08-22 16:46 ` Eliot Moss
2017-08-22 18:25 ` Stephen John Smoogen [this message]
2017-08-25 0:37 ` Either trim quoted text or STOP BOTTOM POSTING (was: alias appears to not work...) L A Walsh
2017-08-25 14:25 ` Either trim quoted text or STOP BOTTOM POSTING cyg Simple
2017-08-25 16:43 ` Dan Kegel
2017-08-26 6:04 ` convenient trimming of quoted text to make points L A Walsh
2017-08-26 15:26 ` cyg Simple
2017-09-01 4:54 ` Duncan Roe
2017-09-01 7:37 ` Csaba Raduly
2017-09-01 12:38 ` cyg Simple
2017-08-22 17:08 ` alias appears to not work inside a called bash script cyg Simple
2017-08-22 17:14 ` Eliot Moss
2017-08-22 19:07 ` cyg Simple
2017-08-22 19:11 ` cyg Simple
2017-08-23 19:08 ` Eric Blake
2017-08-22 19:47 Kaz Kylheku
2017-08-25 2:23 ` L A Walsh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CANnLRdihpyMjU6NyoFMmxiN3SJ22fAYZVprZknoW+JH1uJUi1w@mail.gmail.com \
--to=smooge@gmail.com \
--cc=cygwin@cygwin.com \
--cc=moss@cs.umass.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).