Register
It is currently Sat Dec 20, 2014 12:15 pm

reuse last commands arguments with new command


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sat Aug 06, 2011 2:29 pm   

Joined: Sat Aug 06, 2011 2:02 pm
Posts: 2
Some years ago I read about a script that worked like this:

(22:22)(508)[^^] ~:19 $> egho This is a seven word string
-bash: egho: command not found
(22:22)(509)[oO] ~:19 $> oops echo
This is a seven word string
(22:22)(510)[^^] ~:19 $>

I know about ^foo^bar^ and 'command !!:1-' but I can't make it work like the example above...

anyone?


Top
 Profile  
 PostPosted: Sat Aug 06, 2011 5:23 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
There is no easy way to do it... and you have to use eval(0), unfortunately.

Put this in your .bashrc file:
Code:
oops() {
    local line

    read -r line < <(fc -lnr)

    if [[ $line = *\ * ]]; then
        eval "$1 ${line#*[[:blank:]]}"
    else
        eval "$1"
    fi
}


Here is the one-line version:
Code:
oops() { local line; read -r line < <(fc -lnr); [[ $line = *\ * ]] && eval "$1 ${line#*[[:blank:]]}" || eval "$1"; }

------

« Ego is a structure that is erected by a neurotic individual who is a
member of a neurotic culture against the facts of the matter. And
culture, which we put on like an overcoat, is the collectivized consensus
about what sort of neurotic behaviors are acceptable. » -- Terence McKenna


Top
 Profile  
 PostPosted: Sun Aug 07, 2011 9:49 am   

Joined: Sat Aug 06, 2011 2:02 pm
Posts: 2
Thanks!!
Works like a charm.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP