Làm thế nào để nhanh chóng thay đổi từ đầu tiên trong một lệnh Bash?

Mục lục:

Làm thế nào để nhanh chóng thay đổi từ đầu tiên trong một lệnh Bash?
Làm thế nào để nhanh chóng thay đổi từ đầu tiên trong một lệnh Bash?

Video: Làm thế nào để nhanh chóng thay đổi từ đầu tiên trong một lệnh Bash?

Video: Làm thế nào để nhanh chóng thay đổi từ đầu tiên trong một lệnh Bash?
Video: How To Make Custom PAUSE MENU Screens With Resource Packs! - YouTube 2024, Tháng Ba
Anonim
Nếu quy trình làm việc của bạn có nhiều hành động lặp lại thì sẽ không bao giờ phải tìm cách cải thiện và hợp lý hóa quy trình làm việc của bạn. Bài đăng Hỏi & Đáp của SuperUser hôm nay có một số đề xuất hữu ích cho người đọc đang tìm cách cải thiện quy trình làm việc của mình.
Nếu quy trình làm việc của bạn có nhiều hành động lặp lại thì sẽ không bao giờ phải tìm cách cải thiện và hợp lý hóa quy trình làm việc của bạn. Bài đăng Hỏi & Đáp của SuperUser hôm nay có một số đề xuất hữu ích cho người đọc đang tìm cách cải thiện quy trình làm việc của mình.

Phiên Hỏi & Đáp hôm nay đến với chúng tôi theo lịch sự của SuperUser - một phân khu của Stack Exchange, một nhóm các trang web Hỏi & Đáp do cộng đồng điều hành.

Ảnh chụp màn hình lịch sự của Matt Joyce (Flickr).

Câu hỏi

Đồng xu đọc siêu người dùng muốn biết cách thay đổi nhanh từ đầu tiên trong lệnh 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ó cách nào nhanh hơn cho đồng xu để thay đổi từ đầu tiên trong các lệnh bash?

Câu trả lời

Người đóng góp của SuperUser Spiff, Hastur, jjlin. và Gustavo Giraldez có câu trả lời cho chúng tôi. Đầu tiên, 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.

Tiếp theo là câu trả lời từ 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.

Sau đó, câu trả lời từ jjlin:

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

Và câu trả lời cuối cùng của chúng tôi từ 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.

Có cái gì để thêm vào lời giải thích? Tắt âm thanh trong các ý kiến. Bạn muốn đọc thêm câu trả lời từ những người dùng Stack Exchange có hiểu biết công nghệ khác? Xem toàn bộ chuỗi thảo luận tại đây.

Đề xuất: