커맨드 라인에서 각 파일에 대해 키보드에서 읽은 숫자 k보다 긴 단어 수를 출력하는 쉘 스크립트를 작성해야하며 출력은 단어 수에 따라 정렬되어야합니다. 나는 이러한 오류를 얻을 수 있기 때문에 내가 지금까지 쓴 것은 문제를 해결 나도 몰라 내가 오류를 수정하는 방법을 모른다 : 오류 메시지를 알려줍니다여러 에러 유닉스 쉘
./b.sh: command substitution: line 19: unexpected EOF while looking for matching `''
./b.sh: command substitution: line 20: syntax error: unexpected end of file
./b.sh: command substitution: line 19: unexpected EOF while looking for matching `''
./b.sh: command substitution: line 20: syntax error: unexpected end of file
./b.sh: line 19: 5: command not found
#!/bin/bash
case $# in
0)
echo "The script cannot be executed due to missing arguments!"
exit 1
;;
*)
read -p "Enter the length: " k
n=$k
for file in [email protected]; do
if [ `file $file | egrep "exec|data|empty|reloc|cannot open" > /dev$
continue
else
var=`tr ' ' '\n' < $file | grep -c '^.\{`expr $n`\}$'`
echo $file": "$var
fi
done | sort -n
;;
esac
힌트 : 백틱 대신 '$ (무엇이든)'을 사용하십시오. 그렇게하면 더 명확 해집니다. 또한,'>/dev $'은 무엇입니까? –
다른 '- bash' 스크립트 ('#!/bin/bash'sshbang이있는 스크립트)는'.sh' 확장자를 사용하지 않아야합니다. 이것은 사람들이'sh foo.sh'로 스크립트를 실행할 수 있다는 것을 의미합니다. POSIX sh 동작 만 보장하고 bash 확장은 보장하지 않습니다. 파일 이름 확장자를 전혀 사용하지 말고 shebang ('#!'줄)이 무거운 것을 들게하십시오; 또한 https://www.talisman.org/~erlkonig/documents/commandname-extensions-considered-harmful을 참조하십시오. –
나는 Charles의 충고에 동의하지 않습니다. 쉘에 상관없이'.sh'를 사용하여 쉘 스크립트를 나타냅니다. 그러나 나는 쉘 스크립트를 접미어없이 실행 파일에 컴파일 (compile)한다. 그래서 버전 제어 시스템은'script.sh'를 저장하지만'bin' 디렉토리에'script'가있다. –