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: address@hidden
Subject: Re: Expanding aliases to full command before execution
Date: Wed, 4 Apr 2012 11:27:11 -0400

On Tue, Apr 3, 2012 at 5:22 PM, address@hidden <address@hidden> wrote:
> Hi everyone,
>
> In bash, is it possible to expand my aliases either before they are executed
> or when they are stored in the history file?
> For example, if I have:  alias ll='ls -l'  defined in my .bashrc, when I
> execute "ll" from the command line, I'd like my history file to contain "ls
> -l".  Is there any way to accomplish this?
>
> Thanks,
> Justin
>

I seem to have constructed a solution to my own problem.  I wrote a
function that creates the desired behavior for me and saves it in
$expanded if the argument was in fact an alias.

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
}


Thanks,
Justin



reply via email to

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