DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 30th August 2010
Rubiks Rubiks is offline
New User
 
Join Date: Aug 2010
Posts: 1
Default Executing Builtin with xargs issue

System: Mac OS X 10.6.4

Problem - returning history id through History command and passing to xargs results in failure.

My complete line is: history | grep -m 1 -v -e"history" | awk '/open.*25-2010/ {print $1}' | xargs !

Which basically prints out the identifier (12) for the full line of
12 open ~/Documents/log/08-25-2010.rtf

With 12 being passed to xargs "!12" i get the error:
xargs: !: No such file or directory

I've confirmed by leaving xargs blank that it does receive 12, because that's all it prints out.

From my reading it seems like the problem could be executing a shell script (per man history) within a execution utility.

I'd appreciate if anyone can confim my theory, if they can provide more useful things to read on the man pages, or contribute more things to test out.

The reason I'm using this complicated line instead of ctrl+r is that it seems ctrl doesn't allow me to use the same patterns as I want to in awk or grep.
Reply With Quote
  #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
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing web scripts : can't! erehwon OpenBSD General 3 3rd November 2009 10:02 PM
Possible SMP Issue? MetalHead OpenBSD General 1 25th November 2008 03:52 AM
executing commands for all users when X starts with KDM caesius FreeBSD General 2 20th October 2008 09:03 AM
Executing a c program Libran Programming 13 12th August 2008 11:42 PM
RAM issue nikkon FreeBSD General 5 7th May 2008 04:26 AM


All times are GMT. The time now is 06:56 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick