![복합 명령을 파이프할 수 있나요?](https://linux55.com/image/203589/%EB%B3%B5%ED%95%A9%20%EB%AA%85%EB%A0%B9%EC%9D%84%20%ED%8C%8C%EC%9D%B4%ED%94%84%ED%95%A0%20%EC%88%98%20%EC%9E%88%EB%82%98%EC%9A%94%3F.png)
내 질문은: 파이프는 어떻게 할 수 있나요/어떻게 할 수 있나요?복합 명령( { list; }
)? 부록 B를 참조하세요. 부록 A는 비교 목적으로 제공됩니다.
부록 I:
$ cat << EOF | xargs -n 1 echo
foo
bar
qux
EOF
foo
bar
qux
첨부 B:
$ cat << EOF | xargs -n 1 sh -c '{ var="$1"; echo "$var"; }'
foo
bar
qux
EOF
man sh
:
-c Read commands from the command_string operand
instead of from the standard input. Special parame‐
ter 0 will be set from the command_name operand and
the positional parameters ($1, $2, etc.) set from
the remaining argument operands.
답변1
문제는 sh -c "something"
또 다른 매개변수가 필요하다는 것이다 $0
.
두 번째 예에서는 하나를 제공하지 않으므로 $1
빈 문자열이고 3개의 빈 줄이 표시됩니다. 사용
cat << EOF | xargs -n 1 sh -c '{ var="$1"; echo "$var"; }' inlineshellscript
foo
bar
qux
EOF
food
bar
qux
일반적 으로 대신 을 사용 $0
합니다 .inlineshellscript
sh
inlineshellscript