Bash Command to Do Nothing with Example


When you want to run a command in Bash that does nothing then you can make use of the colon command (:). It is also called a null command.


Example:

$ :
$

As you can see when I just ran the : command it executed successfully and the bash prompt was returned.

To show that the command was a success, let us add some logic.

$ : && echo "The command was successful" || echo "The command failed"

The command was successful

Why would one use "do nothing" command?

    The "do nothing" command is mostly useful in bash scripts, where you have a requirement to satisfy the requirement of having a command as a placeholder that allows the script to continue executing without performing any specific action.


    Script Example:

    #!/bin/bash
    echo "Some logic before doing nothing..."
    :
    echo "Some logic after doing nothing..."
    Do Nothing Bash Command Example
-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap