What I'd like to do is run the same command twice while hitting enter once, with minimum typing. This would be the long version for example:

# sudo puppet agent -tv --server foo.bar && sudo puppet agent -tv --server foo.bar

I thought about

# sudo puppet agent -tv --server foo.bar && !!

..but this runs the previous command (as in the last one that completed), rather than the one I've just typed.

So how do I 'backreference' my command?

Of course this could be done with a for loop or something but I'm guessing there's a more bash-ish / sort-cut-ish way of doing this.


  • This is a question about how I can more quickly manage the servers I administrate at work. How is this off-topic? – spoovy Sep 15 '16 at 11:35

I think the bash-is way here would be either using the history or writing a loop / using variables. I don't think manipulating a not yet executed line is a possible in the way you want to do it.

| improve this answer | |
  • But the command will have been executed by the time the second command (after the &&) runs, no? Seems like this should be doable. – spoovy Sep 13 '16 at 14:12
  • 1
    Not really you are passing a single line to the shell to be executed. The whole line appears in your history, not the two individual commands. The 'shortest' way might be something like: A='cmd' && $A && $A – Unbeliever Sep 14 '16 at 8:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.