
test.sh
내가 넣은 bash 파일에
#!/bin/bash
dirpath="/home/dir"
myfile="$dirpath/file with white space"
awk '{print "firstcolumn"$1":"$4,$2}' ${myfile}.bim >file2
스크립트를 실행하면 sh test.sh
오류 메시지가 나타납니다
awk: fatal: cannot open file '/home/dir/file' for reading (No such file or directory)
. 공백이 있는 파일을 처리하려면 awk를 어떻게 얻나요?
나는 또한 file\ with\white\ space를 시도했지만 작동하지 않습니다.
답변1
인용한 다른 맥락과 정확히 동일합니다.
awk '{print "firstcolumn"$1":"$4,$2}' "${myfile}.bim" >file2
이렇게 하면 전역 문자가 포함된 파일 이름도 방지됩니다.myfile="$dirpath/*"