Create a function that wraps an alias, but prints out the alias string

0

I want to create a bash function that will basically wrap an alias, except that it will output what the alias is doing so I don't forget the actual command.

e.g.:

alias abc='cd ~/root'

So when I run it:

>abc
'you typed: cd ~/root'
/root>

user27449

Posted 2011-12-22T02:23:48.627

Reputation: 5 104

Answers

1

I'm not entirely sure I understand what you want, but here's a function that wraps the creation of an alias that reminds you what it does:

$ reminderalias() {
> alias $1="echo 'You typed: $2'; $2"
> }
$ reminderalias abc 'cd ~/root'
$ abc
You typed: cd ~/root
$ #CWD is now ~/root

Note that this will have trouble with aliases containing certain special characters (mainly single-quotes as far as I can see).

Gordon Davisson

Posted 2011-12-22T02:23:48.627

Reputation: 28 538