"경고: 명령 대체: 입력에서 널 바이트 무시"를 무시해도 되나요?

"경고: 명령 대체: 입력에서 널 바이트 무시"를 무시해도 되나요?

위의 오류 메시지는 무시해도 안전합니까? 아니면 널바이트를 제거할 수 있나요? 제거하려고 시도했지만 tr여전히 동일한 오류 메시지가 나타납니다.

이것은 내 스크립트입니다.

#!/bin/bash                                                                     

monitordir="/home/user/Monitor/"                                                
tempdir="/home/user/tmp/"                                                       
logfile="/home/user/notifyme"                                                   

inotifywait -m -r -e create ${monitordir} |                                     
while read newfile; do                                                          
    echo "$(date +'%m-%d-%Y %r') ${newfile}" >> ${logfile};                     
    basefile=$(echo ${newfile} | cut -d" " -f1,3 --output-delimiter="" | tr -d '\n');
    cp -u ${basefile} ${tempdir};                                               
done

실행 inotify-create.sh하고 새 파일을 만들 때"monitordir"

나는 얻다:

[@bash]$ ./inotify-create.sh 
Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.
./inotify-create.sh: line 9: warning: command substitution: ignored null byte in input

답변1

정확한 질문은 다음과 같습니다.

"경고: ...널 바이트 무시 중..."을 무시해도 되나요?

대답은 '예'입니다. 자신의 코드를 사용하여 널 바이트를 생성하기 때문입니다.
그러나 실제 질문은 "널 바이트"가 왜 필요한가입니다.

inotifywait명령은 다음 형식의 출력을 생성합니다.

$dir ACTION $filename

입력 내용은 다음과 같습니다(hello4 파일의 경우).

/home/user/Monitor/ CREATE hello4

cut 명령은 필드 1과 3을 인쇄하고 null 구분 기호를 사용하면 --output-delimiter=""다음과 같이 null 값이 포함된 출력이 생성됩니다.

$'/home/user/Monitor/\0hello4\n'

null이 추가되었기 때문에 이는 필요한 것이 아닙니다.

해결책은 매우 간단하다는 것이 밝혀졌습니다.
이미 이 명령을 사용하고 있으므로 read다음을 수행하십시오.

#!/bin/bash
monitordir="/home/user/Monitor/"
tempdir="/home/user/tmp/"
logfile="/home/user/notifyme"

inotifywait -m -r -e create ${monitordir} |
    while read dir action basefile; do
        cp -u "${dir}${basefile}" "${tempdir}";
    done

IFS의 기본값을 사용하여 입력을 공백으로 분할한 다음 디렉터리 및 파일 이름만 사용하여 복사합니다.

관련 정보