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..."
Facing issues? Have Questions? Post them here! I am happy to answer!
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
- How to use Autocomplete and Autosuggestion in Shell Commands
- Bash How to Save Output of a Command to a Variable
- How to know the current shell you are logged in?
- How to Echo Bash Command to a File
- Bash Command to Get Absolute Path for a File
- How to Split a String based on Delimiter in Bash Scripting
- Bash: Command Line Arguments to Bash Script Examples
- Bash Command to Download a File From URL
- How to check if a Command Exists using Bash Script
- Ways to Increment a counter variable in Bash Script
- Know Bash shell version command
- Bash command to Read, Output and Manipulate JSON File
- Bash Command to Base64 Decode a String
- Bash Command to Check Python Version
- Bash: Command to Find the Length of a String
- What is $$ in Bash Shell Script- Special Variable
- Bash - How to check if a Command Failed?
- List all Username and User ID using Bash Command
- Command to Sort File In Reverse Order [Unix/Linux/macOS]
- bash: netstat: command not found
- Bash Command To Go Back To Previous Directory
- [Fix] bash: script.sh: /bin/bash^M: bad interpreter: No such file or directory
- How to check your IP using bash for Windows?
- Bash Command To Check If File Exists
- Convert String from uppercase to lowercase in Bash
- 300+ Eclipse IDE Keyboard Shortcuts for Mac - Eclipse
- SharePoint CAML query error - The XML source is not correct - SharePoint
- How to customize SharePoint Modern list form using JSON formatting - SharePoint
- How to highlight the current line in Notepad++ - NotepadPlusPlus
- incorrect line ending: found carriage return (\r) without corresponding newline (\n) - Android
- Send Email with attachment using SharePoint PowerShell, SMTP server - SharePoint
- Fix - zsh: command not found: pip - zsh
- Format Python Code in Visual Studio Code (VS Code) - Python