cancel
Showing results for 
Search instead for 
Did you mean: 
Ian_Lewis
Cadet
Cadet
  • 2,154 Views

Problems with Course Bash Script

Guys

 

I'm doing RH124 and on the Guided Exercise: Controlling Job there is a simple bash script

#!/bin/bash
while true; do
echo -n "$@ " >> ~/control_outfile
sleep 1
done

So I make it executable and when I try and run it I get

line 5: syntax error near unexpected token 'done'

Any ideas where I'm going wrong?

Thanks

Ian

Labels (1)
0 Kudos
4 Replies
Ian_Lewis
Cadet
Cadet
  • 2,140 Views

Okay, so it seems to have been a typing error, but I dont see where.  recreating it seems to work fine. 

Thanks

Ian

0 Kudos
  • 2,120 Views

I just copied-pasted the code and it works fine for me as well

~~~

$ cat test.sh
#!/bin/bash
while true; do
echo -n "$@ " >> ~/control_outfile
sleep 1
done

$ ./test.sh this is a test
^C


$ cat ~/control_outfile
this is a test this is a test this is a test $

~~~


0 Kudos
Ian_Lewis
Cadet
Cadet
  • 2,117 Views

okay, so a bit more info, when you type it, it doesn't process the auto indent, only after the file, with some content entered, can you make it executable and then the indents work on pressing return properly.

0 Kudos
  • 2,113 Views

AFAIK, Bash doesn't require indentation.

As you can see, i just copied pasted and it worked fine (The browser didn't even mess up the double quotes)

I guess there was a hidden character typed by mistake and it wasn't copied at the browser.

If you still have the original file, you can see the hidden characters with ":set list" in Vi(m)

http://chrispian.com/quick-vi-tip-show-hidden-characters/

0 Kudos
Join the discussion
You must log in to join this conversation.