bug-bash
[Top][All Lists]
Advanced

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

Re: Expanding aliases to full command before execution


From: Linda Walsh
Subject: Re: Expanding aliases to full command before execution
Date: Wed, 04 Apr 2012 16:08:04 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.24) Gecko/20100228 Lightning/0.9 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666



jrrandall@gmail.com wrote:

function expand_alias()                 # expand an alias to full command
{
    if [ "$1" = "." ]; then
        argument="\\$1"
    else
        argument="$1"
    fi
    match=$( alias -p | grep -w "alias $argument=" )
    if [ -n "$match" ]; then
        expanded="`echo $match | sed -e s/[^=]*=// | sed 's/^.\(.*\).$/\1/'`"
    else
        expanded="$1"
    fi
}
---

I could see this being an option, because I can think of times I might want one or the other...

I might want to know exactly what I typed, (if only to remind me to use an alias for some long string and save on RSHP (Repetitive-Stress Hit-Points);

But at the same time it would be useful to know what alias(es) were in effect
at the time... (if only the alias was listed!)

so maybe a literal version, followed by (for lines that were 'expanded' by:

        "[" <literal expansion> "]"

Of course the same problem arises with 'functions' as they are said to replace aliases in _almost_ every situation. I.e. do you really want your history file
to be different depending on whether you did
        alias ll=ls\ -l
or
        function ll { ls -l "$@"}
??
Wouldn't they have a similar effect on the accuracy of your record?

Of course, then my idea of literal expansion would get very messy... providing
a practical reason to not do it for functions... (depends on what your requirements are )... ;-)







reply via email to

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