DEV Community

Cover image for Sleep and Open Terminal using While Loop | Shell Scripting
Rahul Mishra
Rahul Mishra

Posted on • Originally published at programmingport.hashnode.dev

Sleep and Open Terminal using While Loop | Shell Scripting

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 ]
        do
            echo "$n"
            (( n++ ))
            sleep(1)
        done
    
  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 ]
      do
        echo "$n"
        (( ++n ))
        gnome-terminal &
      done
    

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

rahulmishra102000@gmail.com

🚀 Other links

GitHub
HackerRank

Top comments (0)