find와 grep과 awk와 vi 를 같이 조합해서 썼을경우 죽는 터미널

cplusman의 이미지

이 부분이 프로그래밍 QnA에 올라와도 되는지 조금 의심스럽습니다만... 그럼에도 불구하고 글을 올리겠습니다.

find와 grep과 awk와 vi 를 같이 조합해서 썼을경우 죽는 문제.

저는 리눅스를 사용하는 프로그래머입니다.

저의 귀차니즘의 발로에서 아래와 같은 명령어를 조합해 봤습니다.

$ find . -name "*.php" -or -name "*.inc" -or -name "*.htm" | xargs grep form | awk -F: '{print $1}' | uniq | xargs vi

위 명령어는 보시면 대충 아시겠지만 현재 디렉토리 하위에서 "form"이란 단어가 포함된 모든 *.php, *.inc, *.htm 파일을
vi로 여는 명령어 입니다.

저는 find와 grep 을 묶어서 alias로 sgrep으로 사용하고 있습니다.

alias sgrep='find . -name '\''*.php'\'' -or -name '\''*.html'\'' -or -name '\''*.htm'\'' -or -name '\''*.inc'\'' -or -name '\''*.php3'\'' | xargs grep '

위의 명령어의 조합을 실행 시켜 보겠습니다.

$ find . -name "*.php" -or -name "*.inc" -or -name "*.htm" | xargs grep form | awk -F: '{print $1}' | uniq | xargs vi

실행하면 vi가 뜨기 바로 전에

Vim : warning : Input is not from Terminal
이란 메시지가 나옵니다.

그리고 현재 디렉토리 하위에서 "form"이란 단어가 포함된 모든 *.php, *.inc, *.htm 파일을
vi로 열어줍니다.

그리고 작업을 마친다음 vi을 빠져나오면 문제가 발생합니다...

vi가 죽어버리는 겁니다. vi가 죽는건지 terminal이 죽는건지 먹통이 되어 버립니다..

위 명령어를 실행시킬때마다 터미널을 새로 띄워야하는 아픔이 있습니다...

오히려 귀차니즘이 더 심해졌습니다... 저의 귀차니즘을 덜어 주실 고수님들 안 계십니까?

왜 vi가 먹통이 되는지 알려주세요...

김충길의 이미지

$ vi `grep -l -H form `find . -name "*.php" -or -name "*.inc" -or -name "*.htm"``

command 치환을 연거푸 쓸수 있나는 테스트 해보지 않아 장담은 못하겠네요.

grep 에서 -H 옵션을 이용하면 매치된 파일명을 출력 할 수 있습니다.
-l 옵션은 다른 내용은 출력 안하죠.

screen + vim + ctags 좋아요~

김충길의 이미지

연거푸 치환은 안되나 봅니다.
그렇다면 아래와 같이 해볼 수 있을거 같네요.

$ TARGETS=`find . -name "*.php" -or -name "*.inc" -or -name "*.htm"`
$ TARGETS=`grep -lH form $TARGETS`
$ vi $TARGETS

김충길 wrote:
$ vi `grep -l -H form `find . -name "*.php" -or -name "*.inc" -or -name "*.htm"``

command 치환을 연거푸 쓸수 있나는 테스트 해보지 않아 장담은 못하겠네요.

grep 에서 -H 옵션을 이용하면 매치된 파일명을 출력 할 수 있습니다.
-l 옵션은 다른 내용은 출력 안하죠.

screen + vim + ctags 좋아요~

cinsk의 이미지

Vim : warning : Input is not from Terminal

이 힌트가 되겠군요.

vim이 terminal을 direct로 control하기 때문에, standard input이 pipe 또는 xarg에서 넘어올 경우, terminal을 제대로 처리하지 못하기 때문에 (특히 vim을 빠져 나올때 원래의 터미널 설정으로 복원하지 못하기 때문)인 것 같습니다.

vim process가 그 session에서 controlling (teminal) process가 아니기 때문일까요.. 저도 이 분야에 대해 잘 몰라서.. :oops:

"Advanced Programming in the Unix Environment"에서 9. Process Relationship, 11. Terminal I/O가 관련되었을 것 같은 생각이 드는군요.
한번 공부해보세요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.