Bagaimana Cara Cepat Mengubah Kata Pertama dalam Perintah Bash?

Daftar Isi:

Bagaimana Cara Cepat Mengubah Kata Pertama dalam Perintah Bash?
Bagaimana Cara Cepat Mengubah Kata Pertama dalam Perintah Bash?

Video: Bagaimana Cara Cepat Mengubah Kata Pertama dalam Perintah Bash?

Video: Bagaimana Cara Cepat Mengubah Kata Pertama dalam Perintah Bash?
Video: Tutorial Memulai Permainan Minecraft: Education Edition #02 - YouTube 2024, April
Anonim
Jika alur kerja Anda diisi dengan banyak tindakan berulang, maka tidak ada salahnya mencari cara untuk meningkatkan dan merampingkan alur kerja Anda. Posting SuperUser Q & A saat ini memiliki beberapa saran yang bermanfaat untuk pembaca yang ingin meningkatkan alur kerjanya.
Jika alur kerja Anda diisi dengan banyak tindakan berulang, maka tidak ada salahnya mencari cara untuk meningkatkan dan merampingkan alur kerja Anda. Posting SuperUser Q & A saat ini memiliki beberapa saran yang bermanfaat untuk pembaca yang ingin meningkatkan alur kerjanya.

Sesi Tanya & Jawab Hari ini hadir untuk memberi kami SuperUser - subdivisi Stack Exchange, pengelompokan situs web Q & A berbasis komunitas.

Screenshot courtesy of Matt Joyce (Flickr).

Pertanyaan

Pembaca koin SuperUser ingin tahu cara cepat mengubah kata pertama dalam perintah 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.

Apakah ada cara yang lebih cepat untuk mengubah kata pertama dalam perintah bash?

Jawabannya

Kontributor Superuser, Spiff, Hastur, jjlin. dan Gustavo Giraldez punya jawabannya untuk kami. Pertama, 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.

Diikuti oleh jawaban dari 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.

Lalu jawaban dari jjlin:

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

Dan jawaban akhir kami dari 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.

Memiliki sesuatu untuk ditambahkan ke penjelasan? Bicaralah di komentar. Ingin membaca lebih banyak jawaban dari pengguna Stack Exchange yang paham teknologi lainnya? Lihat diskusi lengkap di sini.

Direkomendasikan: