Initialise a String

To initialise a string in Bash, use the assignment operator and provide variable as left operand and the value itself as right operand.

Syntax

The syntax to initialise a string in Bash is

</>
Copy
variablename=value

Example

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

Example.sh

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

Output

hello world

Conclusion

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