I will not try to correct your solution, but rather dare to try to give mine for your problem. We also try to eliminate grep, and give opportunity to search:
Code:
$ echo "1,2,3" >/tmp/something
$ echo "4,5,6" >/tmp/something2
$ echo "7,8,9" >/tmp/someother
$ history -c
$ cat /tmp/something
1,2,3
$ cat /tmp/something2
4,5,6
$ cat /tmp/someother
7,8,9
$ aaa(){ a=$1; history | awk -vc="$a" '!/aaa/&&$0~c{print $2,$3}' | sh; }
$ aaa something
1,2,3
4,5,6
$ aaa someother
7,8,9
$ aaa some.*
1,2,3
4,5,6
7,8,9
$
In order for this to work properly, you should instruct
bash to not duplicate same commands in history:
Code:
$ export HISTCONTROL='ignoredups'