J.Doe J.Doe - 3 months ago 9
Linux Question

How to loop a statement in linux

I'm trying to loop a statement/output in linux. So in my ssh directory if I do ls. There is a file call hello.c which prints Hello James. What i'm trying to do is a for loop that prints it 4 times.

This is what i've tried.

for((int i=1;i<=4;i++));
do
./hello.c
echo $i
done


However nothing is printing.

Answer

Bash as a programming language, is dynamically typed, so there are no type declarations. So you can remove the type declaration from the line bellow:

for((int i=1;i<=4;i++));
     ^^^

i.e. change it to

for((i=1;i<=4;i++));

Additionally, are you sure that you can call the program by saying ./hello.c? This is usually the source file and is not executable.