Sleep and Open Terminal using While Loop | Shell Scripting

Subscribe to my newsletter and never miss my upcoming articles

This is a multipart blog article series where I am going to explain the concepts of shell scripting and how to write a shell script in Linux, UNIX or Mac based systems. You can also follow this tutorial blog using windows but for that you have to install a bash from.

In this article we will see that how can we use sleep system call using while loop, and how can we open terminal using while loop in shell script.

  1. Sleep command:
    • If you want to pause the execution of the loop for a while then you can use sleep command.
    • Sleep 1 will pauses the execution of the loop for 1 second.
    •   n=1
        while [ $n -le 3 ]
            echo "$n"
            (( n++ ))
  2. Open terminal:
    • We can open the terminal using the while loop in the shell script.
    • In the loop if we write gnome-terminal & then the terminal which is present in GNOME desktop will get open.
    • n=1
      while [ $n -le 3 ]
        echo "$n"
        (( ++n ))
        gnome-terminal &

Reference code file for this article

So this was all about how to use sleep command and how to open terminal using while loop in shell script. Hope you liked it and learned something new form it.

If you have any doubt, question, quires related to this topic or just want to share something with me, than please feel free to contact me.

📱 Contact Me

Twitter, LinkedIn, Telegram, Instagram,

📧 Write a mail

GitHub, HackerRank

No Comments Yet