[lug] alias or another trick

Davide Del Vento davide.del.vento at gmail.com
Sat Dec 24 16:16:12 MST 2011


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