Bash while loop problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash while loop problem
# 1  
Old 07-21-2007
Bash while loop problem

Hi,

I'm having a problem with the while loop in bash. I try the following script:

#!/bin/bash

while true
do
echo "test"
done

When I try this, it gives me this error:

while: Too few arguments.

What am I doing wrong?

Thanks
# 2  
Old 07-21-2007
I cannot reproduce your problem. My guess is that you are invoking the script wrong somehow so that the wrong shell is running it.

Code:
$ cat bloop
#!/usr/local/bin/bash

while true
do
echo "test"
done
$ ./bloop | head
test
test
test
test
test
test
test
test
test
test
$ csh < bloop
while: Expression Syntax.
$

# 3  
Old 07-22-2007
Thanks. I was wondering if it was something like that. I was sure I had used that same syntax before and it worked.

Thanks again.
# 4  
Old 07-22-2007
Perhaps you named your script "while"?

Last edited by kahuna; 07-22-2007 at 03:45 AM..
# 5  
Old 07-22-2007
i am a beginner in unix, and occasionally i name my scripts after a command name...i have spent hours trying to figure what is wrong before i realized its i have named that script after a command name.
# 6  
Old 07-23-2007
You're right, I named the script "while" Image

Thanks for your help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problem with multiple grep in bash loop

Hello, I am trying to create a matrix of 0's and 1's depending on whether a gene and sample name are found in the same line in a file called results.txt. An example of the results.txt file is (tab-delimited): Sample1 Gene1 ## Gene2 ## Sample2 Gene2 ## Gene 4 ## Sample3 Gene3 ... (2 Replies)
Discussion started by: InfoSeeker2
2 Replies

2. Shell Programming and Scripting

If loop in bash

Hello, I have a script that runs a series of commands. Halfway through the script, I want it to check whether everything is going alright: if it is, to proceed with the script, if it isn't to repeat the last step until it gets it right. My code so far looks like this, simplified a bit: ... (3 Replies)
Discussion started by: Leo_Boon
3 Replies

3. Shell Programming and Scripting

problem access array outside of loop in bash

Below is a test script I was trying to use so that I could understand why the logic was not working in a larger script. While accessing and printing array data inside the while loop, everything is fine. Outside the loop, i guess everything is null?? The for loop that is meant to cycle... (4 Replies)
Discussion started by: adlmostwanted
4 Replies

4. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

5. Shell Programming and Scripting

Problem with for loop in bash

I'm trying to do a script where I want to see if all users home directories are only writable by owner. However, in my script I do not know how to implement the for loop so that all directories are checked. In mine, I am only checking the permissions for the first directory found. I do know that a... (3 Replies)
Discussion started by: detatchedd
3 Replies

6. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

7. Shell Programming and Scripting

bash & Ksh loop problem

hi i was trying to optimize one script and i came across this problem .. i am putting some pseudo code here $ >cat a.sh ls | while read I do i=$(($i + 1)) done echo "total no of files : " $ >ksh a.sh total no of files : $ >bash a.sh total no of files : why is... (1 Reply)
Discussion started by: zedex
1 Replies

8. Shell Programming and Scripting

problem with while loop in BASH shell

I have file named script1 as follows: #!/bin/bash count="0" echo "hello" echo "$count" while do echo "$count" count=`expr $count + 1` done ----------- when I run it, I get ./script1: line 9: syntax error near unexpected token `done' ./script1: line 9: `done' I... (6 Replies)
Discussion started by: npatwardhan
6 Replies

9. Shell Programming and Scripting

bash and ksh: variable lost in loop in bash?

Hi, I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Discussion started by: estienne
2 Replies

10. Shell Programming and Scripting

Simple bash for loop problem

I'm just trying to make a script that runs in command line to echo each line in a text file. Everything i found on google is telling me to do it like this but when I run it it just echos removethese.txt and thats it. Anyone know what im doing wrong? for i in removethese.txt; do echo $i; done ... (4 Replies)
Discussion started by: kingdbag
4 Replies
Login or Register to Ask a Question