Если вы используете режим редактирования Vi в оболочке,то поменять местами два символа легко, просто набрав xp
в обычном режиме («командный режим», т.е. после нажатия Esc). Это буквально означает «стереть символ под курсором», а затем «вставить ранее скопированный текст (удаленный символ )после курсора».
Это будет работать во всех оболочках sh
. Режим Vi описан в стандарте POSIX .
В режиме редактирования Emacs та же операция часто связана с Ctrl+T(T
для "транспонирования" ).
Не существует полностью независимого от оболочки способа сделать это. Вышеприведенное работает в bash
, ksh93
и zsh
, но режим редактирования командной строки Emacs не является стандартным (, как в стандарте POSIX ).
Это из раздела обоснования указанной выше страницы:
In early proposals, the KornShell-derived emacs mode of command line editing was included, even though the emacs editor itself was not. The community of emacs proponents was adamant that the full emacs editor not be standardized because they were concerned that an attempt to standardize this very powerful environment would encourage vendors to ship strictly conforming versions lacking the extensibility required by the community. The author of the original emacs program also expressed his desire to omit the program. Furthermore, there were a number of historical systems that did not include emacs, or included it without supporting it, but there were very few that did not include and support vi. The shell emacs command line editing mode was finally omitted because it became apparent that the KornShell version and the editor being distributed with the GNU system had diverged in some respects. The author of emacs requested that the POSIX emacs mode either be deleted or have a significant number of unspecified conditions. Although the KornShell author agreed to consider changes to bring the shell into alignment, the standard developers decided to defer specification at that time. At the time, it was assumed that convergence on an acceptable definition would occur for a subsequent draft, but that has not happened, and there appears to be no impetus to do so. In any case, implementations are free to offer additional command line editing modes based on the exact models of editors their users are most comfortable with.
Вы хотите добавить пути ко всем файлам, имена которых содержат строку string
, в файл file.txt
с подтверждением для каждого из них.
Вот как это делается с помощьюfind
:
find. -name '*string*' -ok printf '%s\n' {} \; >>file.txt
Опция -ok
запустит указанную утилиту с найденным путем, вставленным вместо {}
, если пользователь ответитy
(илиyes
). Команда find
будет ждать ответа.
На всегда отвечайте y
, используйте
yes | find... >>file.txt
(или измените -ok
на -exec
).
Чтобы всегда отвечать n
, используйте
yes n | find... >>file.txt
Обратите внимание, что ваша исходная команда небезопасна, так как она создает код, включающий имена файлов, как -. Таким образом, специально созданное имя файла может быть использовано для создания кода для выполнения чего-то, что не должно выполняться.