
사용자가 입력한 문자열을 받아 파일 이름을 묻고 해당 문자열이 파일에 있는지 보고하는 쉘 스크립트를 작성하려고 합니다. 아래는 현재 스크립트입니다.
#!/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