cc: [email protected]
Subject: Re: Re: [ast-developers] ksh crash
--------

> 
> >> Also I'd like to ask a question about aliases. Right now, if alias is
> >> set inside of a sourced script, it does not have effect on sourced
> >> script itself. For example:
> >>
> >> testA.sh:
> >> #!/bin/ksh
> >> . ./testB.sh
> >> echo "A\nB\nC\n"
> >>
> >> testB.sh:
> >> alias echo='echo -e'
> >> alias echo
> >> type echo
> >> echo "1\n2\n\3\n"
> >>
> >> output is:
> >> echo='echo -e'
> >> echo is an alias for 'echo -e'
> >> 1\n2\n\3\n
> >> A
> >> B
> >> C
> >>
> >> Is this expected behaviour?
> > Yes, this is documented behavior.  aliases are expanded when reading
> > a script and a dot script is read in its entirety before running
> > any commands.  Therefore, any aliases defined in a . script (or function)
> > will not take effect for that dot script or function.
> >
> > However, profile files are read an processed one command at a time unlike
> > dot scripts.
> 
> Ok, I read the man page, but I asked because I've seen that ksh in 
> opensuse is built with patch that makes alias work in sourced scripts. 
> So I was wondering if they fixed it to work as expected or broke it to 
> work differently than designed.

I did it this way to be compatible with the Bourne shell and since
ksh and Bourne shell were compatible, the standard documented
the behavior.

While the Bourne shell does not have aliases, so this problem doesn't
occur, the dot script needs to compile completely.  Therefore, a
script such as
        echo hello world
        exit
        >%%%%%%<

will run as a script, but not as a dot script with the Bourne shell.

Even if this were changed, users would still have to understand that
aliases defined in compound commands, to not take effect until the
compound command executes.

David Korn
[email protected]
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to