小编che*_*ner的帖子

虽然未找到命令并且在意外标记附近出现语法错误

我正在尝试编写一个 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)

bash shell-script

5
推荐指数
1
解决办法
1144
查看次数

if $( ssh user@host " [ -e file ] " ); 中的“if $”是什么意思?然后 ...?

我看到了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)

shell-script

2
推荐指数
2
解决办法
2493
查看次数

标签 统计

shell-script ×2

bash ×1