Hogyan változtathatjuk gyorsan az első szót egy bash parancsban?

Tartalomjegyzék:

Hogyan változtathatjuk gyorsan az első szót egy bash parancsban?
Hogyan változtathatjuk gyorsan az első szót egy bash parancsban?

Videó: Hogyan változtathatjuk gyorsan az első szót egy bash parancsban?

Videó: Hogyan változtathatjuk gyorsan az első szót egy bash parancsban?
Videó: Szerelmet vallottam a crushomnak?!?! 😱😱🤫🙈 - YouTube 2024, Lehet
Anonim
Ha a munkafolyamat sok ismétlődő művelettel rendelkezik, akkor soha nem fog fájni, hogy megkeresse a munkafolyamat javítását és egyszerűsítését. A mai SuperUser Q & A bejegyzés néhány hasznos javaslatot tartalmaz egy olvasó számára, amely javítja a munkafolyamatát.
Ha a munkafolyamat sok ismétlődő művelettel rendelkezik, akkor soha nem fog fájni, hogy megkeresse a munkafolyamat javítását és egyszerűsítését. A mai SuperUser Q & A bejegyzés néhány hasznos javaslatot tartalmaz egy olvasó számára, amely javítja a munkafolyamatát.

A mai Kérdések és válaszok munkamenetét a SuperUser - a Stack Exchange, a Q & A weboldalak közösség által irányított csoportosulásának részlegével - köszönheti.

Pillanatkép Matt Joyce (Flickr) jóvoltából.

A kérdés

A SuperUser olvasó érme azt szeretné tudni, hogyan lehet gyorsan megváltoztatni az első szót egy bash parancsban:

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.

Van-e gyorsabb mód arra, hogy az érme megváltoztassa az első szót a bash paranccsal?

A válasz

SuperUser közreműködők Spiff, Hastur, jjlin. és Gustavo Giraldez nekünk a választ. Először, 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.

Ezt követte a Hastur válasz:

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.

Aztán a jjlin válasz:

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

És a végső válaszunk Gustavo Giraldez-től:

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.

Van valami a magyarázathoz? Hangzik ki a megjegyzésekben. Szeretne többet válaszolni a többi technikus-tudós Stack Exchange felhasználóiról? Nézze meg a teljes vitafonalat itt.

Ajánlott: