Re-use the previous command output

newcommand $(!!)
The $(!!) will expand to the previous command output (by re-running the command), which becomes the parameter of the new command newcommand.

8
By: lpb612
2011-09-01 21:02:17

These Might Interest You

  • Slightly simpler version of previous sed command that does the same thing. In this case, the output will stop at the command, and the entire command will be terminated as well, instead of proceeding through the whole file.


    1
    command | sed '/regex/q'
    taliver · 2009-12-29 14:52:41 0
  • Pipes the output of the previous command into less. Very useful when command output is too big to fit in a tty console Show Sample Output


    0
    !! | less
    jaykru · 2012-02-03 00:18:42 0
  • cd - would return to the previous directory of your cd command. NB: previous dir is always stored in $OLDPWD variable. Show Sample Output


    1
    cd -
    chmouel · 2009-02-16 02:37:50 0
  • Sometimes easier to just hit these keys to access previous / next commands in history instead of moving your hands all the way to the cursor keys


    0
    <ctrl+p> for previous command; <ctrl+n> for next command
    maheshjagadeesan · 2012-06-01 11:25:09 0

What Others Think

No it won't. It will re-execute the previous command in a subshell. Try this: date echo $(!!) You will get two different lines, instead of two identical lines as you describe.
Mozai · 354 weeks and 6 days ago
May not same as previous O/P
totti · 354 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: