변수 내용에 따라 파이프 명령을 어떻게 확장할 수 있나요?

변수 내용에 따라 파이프 명령을 어떻게 확장할 수 있나요?

연장하고 싶어요이 라인은 오디오 스트림을 녹음하기 위해 /usr/bin/mplayer를 호출합니다..

참조 스크립트는 record.sh병렬로 여러 번 호출될 수 있으며 어떤 컨텍스트에서 오류가 오류 파일에 기록되는지 알아야 합니다.

"$file"그래서 내 질문은: 변수의 내용이 각 줄의 시작 부분에도 인쇄되도록 이 줄을 어떻게 변경할 수 있습니까 ?

"$mplayer" $playlist $url $mplayerflags -msglevel all=2 -dumpstream -dumpfile "$file"  >/dev/null 2>>"$errors" <&2 &

예: 대신:

some arbitrary error message0
some arbitrary error message1
some arbitrary error message2

some arbitrary error message3
some arbitrary error message4
some arbitrary error message5

가지고 싶다:

/home/homedir/recordings/filelocation1.mp3 some arbitrary error message0
/home/homedir/recordings/filelocation1.mp3 some arbitrary error message1
/home/homedir/recordings/filelocation1.mp3 some arbitrary error message2

/home/homedir/recordings/filelocation1.mp3 some arbitrary error message3
/home/homedir/recordings/filelocation1.mp3 some arbitrary error message4
/home/homedir/recordings/filelocation1.mp3 some arbitrary error message5

답변1

줄을 변경하여 이를 수행할 수는 없습니다. 단지 mplayer를 호출하기 전에 줄 바꿈 없이 파일 이름을 인쇄하면 됩니다.

답변2

예를 들어 awk파일 이름 접두사를 각 줄에 파이프할 수 있습니다.

"$mplayer" "${playlist[@]}" "$url" "${mplayerflags[@]}" \
  -msglevel all=2 -dumpstream -dumpfile "$file"  2>&1 > /dev/null |
  F="$file" awk '{print ENVIRON["F"]": "$0}' >> "$errors" &

노트:

  • <&2의미 없는 내용은 삭제했습니다 .
  • 따옴표가 없는 매개변수 확장을 수정했습니다. 제 생각에는 배열이어야 한다고 $playlist생각 합니다.$mplayerflags

관련 정보