Web lists-archives.com

Re: alias appears to not work inside a called bash scripty

On Mon, Aug 21, 2017 at 06:30:15PM -0400, 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.
> Thank you in advance for any insights.
> BTW - I just re-subscribed to cygwin 4-5 hours ago and have not seen any
> mail which seems unusual based on past experience.
> Michel LaBarre
> 613-692-0507
This is expected behaviour. "man bash" gibes

" Aliases are not expanded when the shell is not interactive, unless the
expand_aliases shell option is set using shopt (see the description of shopt

Cheers ... Duncan.

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