[lug] alias or another trick

Davide Del Vento davide.del.vento at gmail.com
Tue Dec 27 12:17:07 MST 2011


Of course there was a small piece missing here (writing in case
someone else will be consulting these archives in future) which is: I
have to export the function, for consumption to the subshells, so the
missing piece was to add

export -f xlC

Unfortunately, though, the python installation process seems to do
something to reset the function and uses the compiler binary even when
I exported the function. So I ended up with an external script and
PATH-fu, which kind-of-worked (btw, I'm not the only one frustrated
with this process:
http://stackoverflow.com/questions/3224934/change-the-gcc-version-that-distutils-uses
)

If you are curious of my current status, I've figured out how to add
missing flags to the compiler from python, but not how to remove ones
that make xlC angry - I guess I'll just parse them all in the shell
script as I'm doing to remove cc_r.

Thanks,
Davide

On Sat, Dec 24, 2011 at 16:16, Davide Del Vento
<davide.del.vento at gmail.com> wrote:
> Cool thanks, this seems exactly what I need, I didn't think about functions.
>
> Btw, the python stuff I'm using is
> http://docs.scipy.org/doc/numpy/reference/distutils.html#numpy.distutils.misc_util.Configuration
> and no, I can't change anything from python side
>
> Cheers,
> Davide
>
> On Sat, Dec 24, 2011 at 15:57, Jeffrey S. Haemer
> <jeffrey.haemer at gmail.com> wrote:
>> Davide,
>>
>> If I understand your question, I agree with Will and Rob. Here's an
>> illustration that illustrates:
>>
>> #!/bin/bash -ex
>>
>> # _xlc=$(which xlC)
>> #xlC() { [ "$1" = "cc_r" ] && shift; $x $*;}
>> _date=$( which date );
>> date() { [ "$1" = "cc_r" ] && shift; $_date $*;  }
>>
>> date
>> date +%Y
>> date cc_r +%Y
>>
>>
>> (I save off the original meaning because, unlike aliases, functions will
>> recurse.)
>>
>> Backing off a step, bash aliases are only meant to be interactive typing
>> shortcuts.  Without special pleading, they won't even work inside scripts.
>>  Running this script
>>
>> #!/bin/bash
>> alias a="echo foo"
>> a
>>
>> will get you
>>
>> line 3: a: command not found
>>
>>
>> As the bash man page says,
>>
>>
>> The rules concerning the definition and use of aliases are  somewhat
>>  confusing.
>> [...]
>> For almost every purpose, aliases are superseded by shell functions.
>>
>>
>> On Sat, Dec 24, 2011 at 12:45 PM, Davide Del Vento
>> <davide.del.vento at gmail.com> wrote:
>>>
>>> Hi all,
>>> I have a script (more on it later) that is compiling a program. It
>>> needs to use two different compilers, namely cc_r and xlC. The problem
>>> is that it has a problem in the way it invokes xlC. It does:
>>>
>>> xlC cc_r <rest-of-the-compiler-arguments>
>>>
>>> I was hoping to fix it with something like
>>>
>>> alias "xlC cc_r"=xlC
>>>
>>> But of course aliases cannot contain spaces (at least in bash on AIX -
>>> sorry this isn't a pure-Linux question). Now, the right answer is "fix
>>> the script", but this is not feasible - the script is python's
>>> distutils and is untouchable and unfixable (today is your lucky day:
>>> I'll spare the long rant on this subject :-)
>>>
>>> An easier trick could be do alias cc_r to nothing, but I can't do
>>> that, since there are other (previous) calls which invoke cc_r alone -
>>> and that part works (after I fixed several other issues, don't think
>>> that it works out of the box :-)
>>>
>>> And by the way, distutils isn't like make (which doesn't recompile
>>> stuff that's already compiled): it recompiles everything, any time is
>>> re-run. So running once, then alias cc_r to nothing and run again will
>>> not work.
>>>
>>> Does anybody have a suggestion on how to fool it? What I would do at
>>> this time is write a script, call it xlC, put it somewhere in the path
>>> earlier than the actual xlC, and use it as "middleman" to the actual
>>> xlC removing the broken cc_r argument (if any). This would work, but
>>> since I'm writing a script to pass to other people for doing this
>>> installation, it's a little too dirty and requires an additional file
>>> (I know I can do it with an herefile, and I would, but still it's
>>> dirtier than the one-liner alias would be).
>>>
>>> Thanks and Merry Christmas!
>>> Davide
>>> _______________________________________________
>>> Web Page:  http://lug.boulder.co.us
>>> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
>>> Join us on IRC: irc.hackingsociety.org port=6667 channel=#hackingsociety
>>
>>
>>
>>
>> --
>> Jeffrey Haemer <jeffrey.haemer at gmail.com>
>> 720-837-8908 [cell], http://seejeffrun.blogspot.com [blog],
>> http://www.youtube.com/user/goyishekop [vlog]
>> פרייהייט? דאס איז יאַנג דינען וואָרט.
>>
>>
>> _______________________________________________
>> Web Page:  http://lug.boulder.co.us
>> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
>> Join us on IRC: irc.hackingsociety.org port=6667 channel=#hackingsociety



More information about the LUG mailing list