True command

This command is referred to as “Do nothing, successfully”. This is because, on a UNIX-based operating system, the main purpose of this command is to return the successful exit status, which also means that it outputs nothing. It should be used if a part of a script always returns true. Its basic syntax is given below:

Syntax:

true [ arguments (optional) ]

It doesn’t matter whether you provide arguments, the true command always returns successfully.

Exit status:

zero (0)
It signifies success

Example :

In this script, we have used true command without any argument.

#!/bin/sh

# true command without any argument
true

Output:

Example:

In this script, we are using the true command with an argument.

#!/bin/sh

# true command using an argument
true GeekforGeeks.txt

Output:

Shell Scripting – True Command

A shell provides an interface with the help of which users can interact with the system easily. To directly interact with a shell, we use an operating system. On a Unix-based operating system, every time we write a command using a terminal, we interact with the system. To interpret or analyze Unix commands, we use a shell. The main job of a shell is to take commands from the user and convert them into the kernel’s understandable form. To summarize this, we can see it as a medium between a user and the kernel system of an OS. The kernel is a computer program that is considered the main part of a computer’s operating system.

This article focuses upon the shell scripting- True command.

Similar Reads

True command:

...

Verify exit status:

We can verify the exit statement of the true command but this command has to be used along with another command. For this purpose, a special shell variable (?) is used to store the status of the true command. This mechanism is illustrated in the below script....

If statement:

We can use the true command even in the if statement. This mechanism is illustrated in the below script....