Bash Scripting - How to Initialize a String Last Updated : 28 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Strings are quite crucial aspects of programming and scripting. We need to store the characters in some variables. In this article, we'll see how to initialize strings in BASH. Basic String Initialization To initialize a string, you directly start with the name of the variable followed by the assignment operator(=) and the actual value of the string enclosed in single or double quotes. Code: #!/bin/usr/env bash a="Hello" echo $a Output: This simple example initializes a string and prints the value using the "$" operator. The "#!/bin/usr/env bash" is the shebang, which makes the kernel realize which interpreter to be run when executing, in our case, it's the BASH interpreter. We have assigned the string "a" a value of "Hello". Also, it must be noted that there should not be any whitespace around the assignment operator otherwise it generates errors in the script. Usage of Double and single Quotes in Strings The double quotes or single quotes might not be significant but when it comes to using variables inside the string, we make use of double quotes to expand the value of the variable. Code: #!/bin/usr/env bash name='Kevin' greet="Welcome $name, to GeeksforGeeks!" echo $greet Output: In the above example, if we don't use double quotes in the "greet" string, the value of the variable "name" would not expand and the string will be displayed as it is. As we can see the variable "name" is not expanded to the value and it is displayed as it is when we use single quotes when we have initialized the string "greet". Comment More infoAdvertise with us Next Article Bash Scripting - How to Initialize a String M meetgor Follow Improve Article Tags : Linux-Unix Bash-Script Similar Reads How to Find Length of String in Bash Script? In this article, we are going to see how to get string length in Bash scripting. Here are a few ways from which we can get the length of the string in BASH: Using the # operatorUsing while loopUsing expr commandUsing awk commandUsing wc command Using these mentioned tools and commands, we will be ab 5 min read Bash Scripting - String Bash String is a data type similar to integer or boolean. It is generally used to represent text. It is a string of characters that may also contain numbers enclosed within double or single quotes. Example: "geeksforgeeks", "Geeks for Geeks" or "23690" are strings Creating a String A basic declarati 2 min read Bash Scripting - Introduction to Bash and Bash Scripting Bash is a command-line interpreter or Unix Shell and it is widely used in GNU/Linux Operating System. It is written by Brian Jhan Fox. It is used as a default login shell for most Linux distributions. Scripting is used to automate the execution of the tasks so that humans do not need to perform them 12 min read Bash Scripting - Substring sIn this article, we will discuss how to write a bash script to extract substring from a string. Extracting an Index-Based Substring There are various ways to obtain substring based on the index of characters in the string: Using cut commandUsing Bash substringUsing expr substr commandUsing awk comm 4 min read Shell Script to Join a String There are different ways to concatenate strings in the shell. Some of them are listed below. String concatenation is used in shell scripting to make it much easier for the user to understand and use the program. Appending strings also allow the programmer to learn the working of concatenation on the 3 min read Like