How to automatically load alias from .bashrc in a bash script?

2011-10-27 Thread Peng Yu
Hi,

I want to use some alias in a bash script. But I have to include the
following line in the script in order to use the alias defined in
~/.bashrc. Is there a way to automatically load the alias from .bashrc
so that I don't have to explicitly include these two lines?

shopt -s expand_aliases
. ~/.bashrc


-- 
Regards,
Peng



Re: How to automatically load alias from .bashrc in a bash script?

2011-10-27 Thread Stephane CHAZELAS
2011-10-27, 11:17(-05), Peng Yu:
> I want to use some alias in a bash script. But I have to include the
> following line in the script in order to use the alias defined in
> ~/.bashrc. Is there a way to automatically load the alias from .bashrc
> so that I don't have to explicitly include these two lines?
>
> shopt -s expand_aliases
> . ~/.bashrc

You mean you'd like every bash script you run on your system to
automatically source your ~/.bashrc.

That sounds like a very unwise thing to do to me,  but that
could be done with:

export BASH_ENV="$HOME/.bashrc"

-- 
Stephane
>
>




Re: How to automatically load alias from .bashrc in a bash script?

2011-10-27 Thread Greg Wooledge
On Thu, Oct 27, 2011 at 04:39:23PM +, Stephane CHAZELAS wrote:
> You mean you'd like every bash script you run on your system to
> automatically source your ~/.bashrc.
> 
> That sounds like a very unwise thing to do to me,  but that
> could be done with:
> 
> export BASH_ENV="$HOME/.bashrc"

He'd still have to turn on the expand_aliases shell option in each
script, though.  Unless he puts it in .bashrc.

(Might as well hand him enough rope to hang himself.)

If you want to do things properly, use functions instead of aliases.
They are more powerful and more flexible.



Re: How to automatically load alias from .bashrc in a bash script?

2011-10-27 Thread Peng Yu
On Thu, Oct 27, 2011 at 11:43 AM, Greg Wooledge  wrote:
> On Thu, Oct 27, 2011 at 04:39:23PM +, Stephane CHAZELAS wrote:
>> You mean you'd like every bash script you run on your system to
>> automatically source your ~/.bashrc.
>>
>> That sounds like a very unwise thing to do to me,  but that
>> could be done with:
>>
>> export BASH_ENV="$HOME/.bashrc"
>
> He'd still have to turn on the expand_aliases shell option in each
> script, though.  Unless he puts it in .bashrc.
>
> (Might as well hand him enough rope to hang himself.)
>
> If you want to do things properly, use functions instead of aliases.
> They are more powerful and more flexible.

Thanks for the input. I have some somecommonname.sh, which may be
conflict with other commands. Therefore, I only need to rename them to
avoid name conflict. But I'm not using any arguments. I think that
creating symbolic link rather than alias probably is a better
solution.


-- 
Regards,
Peng