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 Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

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