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

Re: makefile not taking aliases into account



On Sun, May 08, 2005 at 10:17:11PM -0400, Michael Marsh wrote:
> On 5/8/05, Kamaraju Kusumanchi <kk288@cornell.edu> wrote:
> > Hi
> >     Using Debian sid. I have an alias in my .bashrc say something like
> > 
> > alias x="y"
> > 
> > This command is executing fine on a bash shell (ie I can use x). But
> > when I use x in a makefile, it is not getting expanded to y. Is this a
> > future? How can I overcome this limitation?
> 
> Unless you've told it otherwise, make isn't using bash, it's using sh.
>  While sh is probably a symlink to bash, when invoked as "sh" it
> doesn't read your .bashrc (nor the system default).  You can change
> this behavior with the SHELL variable in your makefile:
> 
> SHELL := /bin/bash
> 
> In general, though, it's better to set everything that you need in the
> makefile, since relying on your aliases makes your makefile highly
> non-portable.  I usually do something like (using your example):
> 
> X := y
> 
> and then using $(X) instead of the alias x in commands.

In addition to what's been said, also note that - if you're explicitly
asking bash to execute the script - it holds that "Aliases are not
expanded when the shell is not interactive, unless the expand_aliases
shell option is set using shopt..." (man bash).  So, if you write

#!/bin/bash
alias ll='ls -l'
ll

you'll get "ll: command not found", while the next two incantations
work as many people would expect:

#!/bin/sh
alias ll='ls -l'
ll

#!/bin/bash
shopt -s expand_aliases
alias ll='ls -l'
ll

Thus, depending on the details of usage, it's kind of a feature...
But don't worry, you're not the first to overlook that little phrase in
the man page :)

Almut



Reply to: