변수가 아닌 명령줄에 직접 명령을 출력합니다.

변수가 아닌 명령줄에 직접 명령을 출력합니다.

저는 bash 셸을 사용하고 있으며 명령이 실행된 후 나타나는 명령 프롬프트에 명령 출력이 직접 나타나기를 원합니다!

내 아이디어를 설명하기 위해 구상한 예는 다음과 같습니다.

locate create_tables.sql|MAGIC_command
user@localhost:~# /usr/share/doc/phpmyadmin/create_tables.sql

이제 다음과 같이 dsubstitution 명령을 사용하십시오.

sudo $(locate create-tables.sql)

유효하지만 즉시 실행출력되기 전에 편집할 수 있기를 원합니다. 어떤 방법이 있나요?

답변1

Emacs 모드에서는 sudo $(locate create-tables.sql), Esc, Control+를 입력합니다.e

shell-expand-line바라보다배쉬 참조 매뉴얼:

껍질처럼 선을 확장하십시오. 별칭 및 기록 확장은 물론 모든 쉘 단어 확장도 수행됩니다.

답변2

저는 주로 이런 일을 할 때 클립보드를 사용합니다.

$ some_command | cb
$ cb_edit
$ `cb` #or paste it with your paste button/shortcut

마법:

 cb() {
  if [ ! -t 0 ]; then
    #if somebody's piping in reproduce input and pipe a copy to the clipboard
    tee >(xclip -selection c)
  else
    #otherwise, print the contents of the clipboard
    xclip -selection c -o 
  fi
}
cb_edit() { cb | vipe "$@" | cb; }

답변3

덜 우아한 해결책은 출력을 일부 tmpfile에 저장하고 해당 파일을 편집한 후 다음을 실행하는 것입니다.

$ locate create_tables.sql > /tmp/tmpfile
$ vi !$    # last argument of last command
$ bash !$

관련 정보