0

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.

Thanks

closed as off-topic by Iain, yoonix, mdpc, Jenny D, HBruijn Sep 14 '16 at 15:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – yoonix, mdpc, HBruijn
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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
2

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.

  • 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.