!["경고: 명령 대체: 입력에서 널 바이트 무시"를 무시해도 되나요?](https://linux55.com/image/101872/%22%EA%B2%BD%EA%B3%A0%3A%20%EB%AA%85%EB%A0%B9%20%EB%8C%80%EC%B2%B4%3A%20%EC%9E%85%EB%A0%A5%EC%97%90%EC%84%9C%20%EB%84%90%20%EB%B0%94%EC%9D%B4%ED%8A%B8%20%EB%AC%B4%EC%8B%9C%22%EB%A5%BC%20%EB%AC%B4%EC%8B%9C%ED%95%B4%EB%8F%84%20%EB%90%98%EB%82%98%EC%9A%94%3F.png)
위의 오류 메시지는 무시해도 안전합니까? 아니면 널바이트를 제거할 수 있나요? 제거하려고 시도했지만 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의 기본값을 사용하여 입력을 공백으로 분할한 다음 디렉터리 및 파일 이름만 사용하여 복사합니다.