LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Scripting question!!!!! help, plz! (https://www.linuxquestions.org/questions/linux-newbie-8/scripting-question-help-plz-184853/)

madmatt112 05-23-2004 11:51 AM

Scripting question!!!!! help, plz!
 
Hello people! I made this script to run the command "who" every 30 seconds:

#!/bin/bash
#include<stdio.h>

main()
{
int number;
number=1;
sleep 30;
who;
sleep 30;
who;
sleep 30;
who;
if number=1 then
goto main;
}

:confused:
But for some odd reason it gives me this:

./test: line 16: syntax error near unexpected token `}'
./test: line 16: `}'

But isn't that supposed a CLOSING bracket?! :scratch: Please help me out, here people!

b0uncer 05-23-2004 12:05 PM

umm correct me if I'm wrong, but I've thought that bash scripting is a bit different thing than C-programming...I mean, the main() { } -function seems to me like a normal C-function, but is it the same in bash-scripting? I haven't done that that much...

if you want to do bash-scripting, I'd suggest read at least first

man bash

or visit some website telling about bash's way of working...

lyle_s 05-23-2004 12:11 PM

I'm afraid you're getting C and bash very mixed up. Here's how I'd do it;
Code:

#!/bin/bash

while :
do
        who
        sleep 30
done

One good resource is the Advanced Bash-scripting Guide (http://www.tldp.org/LDP/abs/html/). Don't let the "Advanced" part worry you.

Lyle

wrongman 05-23-2004 12:16 PM

Code:

#!/bin/bash

LOOP=0

while [ $LOOP -lt 10 ]; do
        who
        sleep 5
done

here it is ;-)

wrongman 05-23-2004 12:17 PM

sorry, didn't see that lyle already answered

madmatt112 05-23-2004 03:16 PM

Wow! Thank you all VERY much :) I tested them out, and they work! Oh, and, Lyle_s thanks for that great link! Again, thank you so much!


All times are GMT -5. The time now is 05:30 AM.