2

I am attempting to achieve the effect of a batch file that does something similar to the following concept:

:start
ECHO 1
ECHO 2
ECHO 3
ECHO 4
ECHO 5
goto start

That is how I would make a batch file in Windows, but I am new to Linux, and would like to achieve a similar idea here in this operating system.

3
  • while true ; do echo 1 ; echo 2 ; echo 3 ; echo 4 ; echo 5 ; done
    – FedKad
    Nov 23, 2019 at 11:33
  • goto is very bad programming practice. Learn about the control loops in bash.
    – vanadium
    Nov 23, 2019 at 13:01
  • Somewhat related: How to deal without goto in Bash? Nov 23, 2019 at 13:24

1 Answer 1

3

In bash scripting you do not have gotos; you should use a while loop. For the while loop to run endlessly, you can use the true command which returns status of 0 (meaning successful run of a command).

So, you can create your "endless" loop like this:

while true ; do
  echo 1
  echo 2
  echo 3
  echo 4
  echo 5
done 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.