Simple looping in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple looping in shell
# 1  
Old 05-20-2015
Simple looping in shell

Hii all.
I have a problem with my shell script.
This is my code
Code:
while [ $count -le 13526 ]
do
    space.exe inputs/gr$count >> outputs/t$count
    count=$[$count+1]
done

I ussually work in cygwin. When i tried in linux(ubuntu, kali linux) i found error said
Code:
Syntax error : end of file unexpected (expecting "do")

Need a really fast help for that Smilie. Thank you..
# 2  
Old 05-20-2015
Hello weslyarfan,

What is the value of count going into the loop?
What shell are you using?
If you add this line into your code, it might show you more detail about what is going wrong:-
Code:
set -x

With ksh as my shell, the syntax count=$[$count+1] doesn't give a numeric output, and so the while loop fails with a syntax error. It works fine in bash though.



Robin
# 3  
Old 05-20-2015
I am really new in linux att all. So actually I dont know ho to answer your question.

I run it with terminal in Ubuntu and the error result is like I have shown before.
So, How is the manner to run that code in Ubuntu terminal?
# 4  
Old 05-20-2015
Okay, no problem. What output do you get from printf $SHELL ?

I expect it will say bash but it's best to check.

You could probably get away with running this for any shell:-
Code:
$SHELL -x your_script

You should see a more explicit running of you code including many of the values being set or tested. It could be quite large, but the last block of lines before the failure will be where the interesting bit will be. Is the overall script quite large or can you post it (in CODE tags)



Robin
# 5  
Old 05-20-2015
Probably just missing count=0 before the posted code.
# 6  
Old 05-20-2015
The $[ ] syntax is rather obsolete these days. If your shell supports it, the more modern COUNT=$((COUNT+1)) is recommended.
# 7  
Old 05-27-2015
I have tried to print $SHELL in my terminal and the result is
Code:
/bin/bash

what should i try to run the code shown in upstair?

---------- Post updated at 08:30 PM ---------- Previous update was at 08:21 PM ----------

Thank You Corona688. Your suggest is worked.

Last edited by weslyarfan; 05-27-2015 at 10:22 AM.. Reason: wrong code
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting looping issue

#!bin/ksh --------------------------------------------------------------------------------------------- -- Get sequence number from database --------------------------------------------------------------------------------------------- .os rm... (3 Replies)
Discussion started by: swathi reddy1
3 Replies

2. Shell Programming and Scripting

Looping not completing in shell script

Hi, Iam using below code to login to servers to get cpu utilisation. but output is coming for only one server. code is below root@blr-svr-oclan-01 # more SSSC_CPU_UTIL1.sh #!/bin/sh echo "CPU UTILIZATION" while read line; do IDLE=`/usr/local/bin/sshpass -p 'xxx' ssh xxx@$line 'sar 2 2' |... (1 Reply)
Discussion started by: surender reddy
1 Replies

3. Shell Programming and Scripting

Help with looping in shell scripting

Hi there im totally new to shell scripting and i find it very interesting. I come from java programming background. Basically what i need is to loop a string of say all possible permutations of 20 displayable characters and md5 hash the string till it produces a 128 bit hash value with say 4... (17 Replies)
Discussion started by: jremio
17 Replies

4. Shell Programming and Scripting

help while looping simple noobie

hi guys i have linked my lab 15. i have no idea where to start i dont understand whats it asking me. about the screen shot part!.. if someone can take a quick look and help me out with this unix lab that would be great.. i have did the Required Errorlevels Errorlevel #Event Information ... (1 Reply)
Discussion started by: beerpong1
1 Replies

5. Shell Programming and Scripting

C Shell Script: While function not fully looping

I am new to scripting and this is probably the 4th or 5th simple script I have written. I am working with a HUGE number of data that need to be organized into folders and named a certain way. I wrote the naming script using a while function to go through the 1000-some folders and rename the files... (0 Replies)
Discussion started by: notluckyhannah
0 Replies

6. Shell Programming and Scripting

[Solved] help me in this looping in shell scripting

Hi, #!/bin/ksh result='/TIA/app/UniQP/queue/document/CSB' i=0; while ; do i=`expr $i + 1` if ($i -lt 5);then echo "THerrFile_$i.err"; else break; fi done ... (0 Replies)
Discussion started by: sudhir_83k
0 Replies

7. Shell Programming and Scripting

Looping through a shell script with sql statements

Hello members, I'm working on the Solaris environment and the DB i'm using is Oracle 10g. Skeleton of what I'm attempting; Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a... (4 Replies)
Discussion started by: novice82
4 Replies

8. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

9. Shell Programming and Scripting

Convert shell script for looping

Situation: I have a working shell script on our file server (OSXS Tiger) to connect to a workstation, which is using a portable home directory (phd), and rsync a user's MirrorAgent.log. I'm not that strong of a scripter (obviously), but I would like to add other workstations to this script as they... (4 Replies)
Discussion started by: le0pard13
4 Replies

10. Shell Programming and Scripting

looping through a variable in a shell script

hi, my first question is :- i would like to know how do i loop through the output of a variable. for ex:- if i have a variable called x and echo $x gives the output like feb 19 07 feb 20 07 feb 21 07 i would like to know how do i loop through this since it is separated and i... (1 Reply)
Discussion started by: ramachandranrr
1 Replies
Login or Register to Ask a Question