![예상치 못한 토큰 근처에서 명령을 찾을 수 없으며 구문 오류가 발생했습니다.](https://linux55.com/image/58055/%EC%98%88%EC%83%81%EC%B9%98%20%EB%AA%BB%ED%95%9C%20%ED%86%A0%ED%81%B0%20%EA%B7%BC%EC%B2%98%EC%97%90%EC%84%9C%20%EB%AA%85%EB%A0%B9%EC%9D%84%20%EC%B0%BE%EC%9D%84%20%EC%88%98%20%EC%97%86%EC%9C%BC%EB%A9%B0%20%EA%B5%AC%EB%AC%B8%20%EC%98%A4%EB%A5%98%EA%B0%80%20%EB%B0%9C%EC%83%9D%ED%96%88%EC%8A%B5%EB%8B%88%EB%8B%A4..png)
사용자가 입력한 문자열을 받아 파일 이름을 묻고 해당 문자열이 파일에 있는지 보고하는 쉘 스크립트를 작성하려고 합니다. 아래는 현재 스크립트입니다.
#!/bin/bash
while :
do
echo "Please enter a string"
read input_string
echo "Please enter the file name to see if that string is present in it - (Enter .abw after)"
read input_string1
grep -q "${input_string}" "${input_string1}"
if grep -q $input_string $input_string1 ; then
echo "Your string has been found"
else
echo "Your string has not been found"
fi
done
스크립트를 실행하면 다음과 같이 표시됩니다.
Line 2: while:: command not found
Line 3: syntax error near unexpected token 'do'
Line 3: 'do'
누구든지 나를 올바른 방향으로 가리킬 수 있다면 매우 감사하겠습니다.
답변1
실제로 두 개의 grep 줄이 필요하지 않으며 대신 다음을 입력할 수도 있습니다.
if grep -q "$input_string" "$input_string1" ; then
echo "Your string has been found"
else
echo "Your string has not been found"
fi