Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax error near unexpected token `echo'

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' "

.

#!/bin/sh
echo $1;
declare -a values=$(ssh -q  jboss@$1 "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?

like image 317
user2986175 Avatar asked Dec 18 '13 18:12

user2986175


People also ask

What does syntax error near unexpected token `(' mean?

This error message also surfaces when you are entering commands in the Linux command line for everyday tasks such as copying files manually etc. The main reasons why this error message occurs is either because of bad syntax or problem of the OS in interpreting another system's commands/shell.


1 Answers

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

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

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

like image 64
Guntram Blohm Avatar answered Oct 12 '22 03:10

Guntram Blohm