LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-02-2012, 01:26 PM   #1
chaacoali
LQ Newbie
 
Registered: Apr 2012
Posts: 18

Rep: Reputation: Disabled
Can someone plz tell me how to correct this code


Hi this is an sh file to plot values in an xgraph.
Code:
for j in dcma 802_11
{
rm -rf result_$j
rm -rf PDR_$j DELAY_$j THROUGHPUT_$j LOSS_RATIO_$j AVG_ENERGY_$j RESIDUAL_ENERGY_$j
for i in 0.09 0.089 0.088 0.085 0.084
{
	ns dcma.tcl $i $j &> output
	gawk -f analysis.awk out.tr >> result_$j
}
}

for j in dcma 802_11
{
echo "$j"
gawk 'BEGIN{x=1;}{ print x " " $1; x+=1 }' result_$j >> PDR_$j
echo " "
gawk 'BEGIN{x=1;}{ print x " " $2; x+=1 }' result_$j >> DELAY_$j
echo " "
gawk 'BEGIN{x=1;}{ print x " " $3; x+=1 }' result_$j >> THROUGHPUT_$j
echo " "
gawk 'BEGIN{x=1;}{ print x " " $4; x+=1 }' result_$j >> LOSS_RATIO_$j
echo " "
gawk 'BEGIN{x=1;}{ print x " " $5; x+=1 }' result_$j >> AVG_ENERGY_$j
echo " "
gawk 'BEGIN{x=1;}{ print x " " $6; x+=1 }' result_$j >> RESIDUAL_ENERGY_$j
echo " "
}


for i in PDR_ DELAY_ THROUGHPUT_ LOSS_RATIO_ AVG_ENERGY_ RESIDUAL_ENERGY_
{
	xgraph $i'dcma' $i'802_11' -lw 2 -x "$i" -y "Rate (Mbps)" -t "$i"
}
When I try executing this file. I'm getting the following errors.
[root@localhost script1]# sh script.sh
'cript.sh: line 2: syntax error near unexpected token `{
'cript.sh: line 2: `{


Can someone please help me.
Thanks in advance.
 
Old 05-02-2012, 01:31 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
What language are you using for this? You do not have a shebang declaring the language. Also that is not the standard syntax for a bash for loop, see: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html

If you are wanting bash to execute the code inside of your {} you would need to add a dollar sign in front and switch it to ().
 
Old 05-02-2012, 01:32 PM   #3
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Notice you have no 'do' and 'fi' statements as well.

Correction: 'fi' is the close for an 'if' statement. You will use 'done' to close your for loop.
 
Old 06-12-2012, 07:59 AM   #4
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,329

Rep: Reputation: 254Reputation: 254Reputation: 254
Using {} for a for loop works in bash, although Iím puzzled where this is documented:
Code:
$ for i in 1 2 3; { echo $i; }
1
2
3
as do and { arenít interchangeable.

But as itís started by sh, maybe itís the real sh and hence not working. Is:
Code:
$ bash script.sh
working as expected? When itís given as argument, there is also no need to include the shebang in the script file.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] please correct me on my code? hadimotamedi Linux - Newbie 3 12-04-2010 04:47 AM
explain me this c code plz alaios Programming 1 06-03-2005 06:32 AM
Is this C code correct ? redsea Programming 4 10-23-2004 03:48 AM
Can you check my grub boot loader code and correct? Bensoft Kill MS Linux - Newbie 1 10-07-2003 05:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration