View Single Post
  #2   (View Single Post)  
Old 31st August 2010
s0xxx's Avatar
s0xxx s0xxx is offline
Package Pilot
 
Join Date: May 2008
Posts: 192
Default

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'
__________________
The best way to learn UNIX is to play with it, and the harder you play, the more you learn.
If you play hard enough, you'll break something for sure, and having to fix a badly broken system is arguably the fastest way of all to learn. -Michael Lucas, AbsoluteBSD

Last edited by s0xxx; 31st August 2010 at 02:21 PM. Reason: corrected mistake
Reply With Quote