Sample Header Ad - 728x90

Using bash history expansion, how do I rerun the last command with a different last word?

0 votes
1 answer
87 views
*NOTE: I plan on answering my own question.* This is the last command I ran on the command line: git co head -- a/path/to/a/file.ts I want to run this a few more times but with different file paths for the last argument/parameter. This page explains history expansion , and I think the answer I'm looking for is in this subsection , but it lacks examples. Using history expansion, how would I rerun the previous command with a different file path? For example, how would I run: git co head -- a/path/to/another/different-file.ts --- This is probably a duplicate but I haven't been able to find the answer I'm looking for. These posts look like they might have the answer but they didn't: - https://unix.stackexchange.com/questions/60781/rerunning-the-same-command-with-a-different-parameter - https://unix.stackexchange.com/questions/236506/replace-the-last-word-of-last-command-but-keep-the-first
Asked by Daniel Kaplan (1070 rep)
Sep 29, 2024, 08:54 PM
Last activity: Sep 29, 2024, 09:30 PM