help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How to use alias defined in calling shell?


From: Dan Douglas
Subject: Re: [Help-bash] How to use alias defined in calling shell?
Date: Fri, 29 May 2015 13:08:51 -0500

On Tue, May 26, 2015 at 7:17 AM, Greg Wooledge <address@hidden> wrote:
> On Mon, May 25, 2015 at 06:27:08AM -0500, Dan Douglas wrote:
>> I always suggest doing this manually.
>>
>> $ ( shopt -s expand_aliases; alias a='echo the alias'; export BASHOPTS
>> myAliases=$(typeset -p BASH_ALIASES); bash -xc $'eval "$myAliases"\n a' )
>
> And I suggest not doing it at all.  How are you going to be able to trust the
> script if it picks up random garbage from the caller and treats it as code?
>

I don't see a problem. Presumably you called the script and control the
environment prior to calling the child shell. Bash doesn't allow BASH_ALIASES
to be inherited so there is no chance of a problem being inherited from what
called the current shell. It might be better to limit the scope further by just
bringing in a specific alias, and it would be more portable to get the alias
definition by calling `alias` rather than using typeset.

This is no different from the numerous other things a parent shell has to
control if it can't assume a clean environment. This is less likely to harm you
than a "shellshock" assuming someone can set an arbitrary environment variable
to an arbitrary value. You should run child shells with `env -i` in that case.
`typeset -p` guarantees (hopefully) a well-formed array assignment and won't
automatically execute code.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]