Come modificare rapidamente la prima parola in un comando Bash?

Sommario:

Come modificare rapidamente la prima parola in un comando Bash?
Come modificare rapidamente la prima parola in un comando Bash?

Video: Come modificare rapidamente la prima parola in un comando Bash?

Video: Come modificare rapidamente la prima parola in un comando Bash?
Video: Minecraft - How To Add Custom Splash Texts! - YouTube 2024, Aprile
Anonim
Se il tuo flusso di lavoro è popolato da molte azioni ripetitive, non fa mai male cercare modi per migliorare e ottimizzare il tuo flusso di lavoro. Il post di Q & A di SuperUser di oggi contiene alcuni suggerimenti utili per un lettore che cerca di migliorare il proprio flusso di lavoro.
Se il tuo flusso di lavoro è popolato da molte azioni ripetitive, non fa mai male cercare modi per migliorare e ottimizzare il tuo flusso di lavoro. Il post di Q & A di SuperUser di oggi contiene alcuni suggerimenti utili per un lettore che cerca di migliorare il proprio flusso di lavoro.

La sessione di domande e risposte di oggi ci viene fornita per gentile concessione di SuperUser, una suddivisione di Stack Exchange, un raggruppamento di domande e risposte basato sulla comunità.

Schermata per gentile concessione di Matt Joyce (Flickr).

La domanda

La moneta del lettore SuperUser vuole sapere come cambiare rapidamente la prima parola in un comando bash:

I would like to improve my workflow in bash and realized that I often want to execute the same command to a different executable.

Some Examples

1.) Git

2.) Bash
2.) Bash
Image
Image

I know that I can hit Ctrl+a then Del to remove the first word, but I am wondering if there is a quicker way to do it.

C'è un modo più veloce per moneta per cambiare la prima parola in comandi bash?

La risposta

Collaboratori SuperUser Spiff, Hastur, jjlin. e Gustavo Giraldez ha la risposta per noi. Prima su, Spiff:

!$ expands to the last word of your previous command. So you could do:

Or
Or
Your examples happened to only repeat the last word, so !$ worked fine. If you actually had a lot of arguments that you wanted to repeat, and you just wanted to change the first word, you could use !*, which expands to all words of the previous command except the zeroth.
Your examples happened to only repeat the last word, so !$ worked fine. If you actually had a lot of arguments that you wanted to repeat, and you just wanted to change the first word, you could use !*, which expands to all words of the previous command except the zeroth.

See the “HISTORY EXPANSION” section of the bash man page. There is a lot of flexibility there.

Seguito dalla risposta di Hastur:

I would like to add a warning (see the answer from Spiff above). With !$, you do not have full visual control of the line you are running. The results can be harmful sometimes, especially if you incur a misprint. It takes what it needs from the history to expand on.

So if you write the last command with a blank space at the beginning, then this command will probably not finish from the history. When you execute your new command with !$, the shell will not take the parameters from the last command line typed, but only from the last part of the history.

Here are some more helpful words and commands.

Quindi la risposta di jjlin:

Ctrl+a to go to the beginning of the line, then Alt+d to delete the first word.

E la nostra risposta finale di Gustavo Giraldez:

The delete word shortcut is actually Meta+d, and Meta is usually mapped to Alt on Linux machines. On platforms where this is not the case, an alternative to get the Meta modifier is to use Esc as a prefix. You can read more about the Meta Key here.

Hai qualcosa da aggiungere alla spiegazione? Audio disattivato nei commenti. Vuoi leggere più risposte dagli altri utenti di Stack Exchange esperti di tecnologia? Controlla la discussione completa qui.

Consigliato: