On Tue, Apr 3, 2012 at 5:22 PM, jrrand...@gmail.com <jrrand...@gmail.com> 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