我正在尝试编写一个 shell 脚本,该脚本从用户那里获取字符串输入,询问文件名并报告该字符串是否存在于文件中。下面是我当前的脚本。
#!/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
Run Code Online (Sandbox Code Playgroud)
当我运行脚本时,它说
Line 2: while:: command not found
Line 3: syntax error near unexpected token 'do'
Line 3: 'do' …Run Code Online (Sandbox Code Playgroud) 我看到了if语句中条件使用 a 的脚本,但$
我不明白为什么?
if $( ssh user@host " test -e file " ); then
echo "File is there"
else
echo "We don't that file on that host"
fi
Run Code Online (Sandbox Code Playgroud)