bash 意外标记“echo”附近的语法错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20666207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 00:33:18  来源:igfitidea点击:

syntax error near unexpected token `echo'

bashshellsshjboss

提问by user2986175

I am trying to execute the following code with an IP address as a parameter from the commandline; however I am getting an error saying - ": line 6: syntax error near unexpected token `echo' "

我正在尝试使用 IP 地址作为命令行中的参数执行以下代码;但是我收到一条错误消息:“:第 6 行:意外标记‘echo’附近的语法错误”

.

#!/bin/sh
echo ;
declare -a values=$(ssh -q  jboss@ "ps -eo pcpu,pid,user | sort -r -k1 | less | grep jboss");
for value in ${values[*]} do
   echo $value;
done

Please can you help me rectify this error?

请你能帮我纠正这个错误吗?

回答by Guntram Blohm supports Monica

Put a ;in front of the do, or put the do on a new line.

将 a;放在 do 之前,或将 do 放在新行中。

for value in ${values[*]}; do
  echo $value
done

The ;behind "echo $value" isn't needed except if you write the donedirectly behind it.

;不需要,如果你写的除了后面“回声$值”done直接背后。