Reputation: 128
Is there a way to "expand" a bash alias on the command-line and get the command behind it? So it for instance would turn ls into;
ls --color=auto
I keep getting into situations when my aliases does almost what I want to do, but not exactly...
Is this possible all suggestions or answers appreciated
Upvotes: 0
Views: 236
Reputation: 26447
And a much more complex way, which is suitable for echoing:
$ cut -d = -f1 --complement< <(alias alias_name) | tr '"'"'" ' '
So, in a function like
exp() {
cmd=$1
shift
echo $(cut -d = -f1 --complement< <(alias $cmd) | tr '"'"'" ' ') $@
}
would result in echoing the command as it would be issued to the shell, after all expansions are in place.
This might be useful for debugging.
$ exp ll .*
ls -l --color=tty . .. .bash_history .bash_logout .bash_profile .bashrc .lesshst
Upvotes: 1
Reputation: 5335
Try
$ alias alias_name
It will show you the expansion of the given alias name
Upvotes: 1