Print String to Output

To print a string in Bash, use echo command. Provide the string as command line argument to echo command.

Syntax

The syntax to initialise a string in Bash is

</>
Copy
echo string_variable_or_value

Examples

In the following examples, we cover scenarios where we print a string value or print a value in variable to output, using echo command.

Print String Value to Output

In the following script, we print the string value “hello world” to output.

Example.sh

</>
Copy
echo "hello world"

Output

hello world

Print String Value in Variable to Output

In the following script, we initialise a variable with string value “Hello World” and print it to output.

Example.sh

</>
Copy
str="hello world"
echo $str

Output

hello world

Conclusion

In this Bash Tutorial, we have learnt how to print a string to output in Bash shell.