Bash Scripting - How to Initialize a String Last Updated : 28 Nov, 2021 Comments Improve Suggest changes 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 Bash Scripting - How to Run Bash Scripting in Terminal In this article, we are going to see how to run bash script in terminal. For example, we create a bash file set of instructions or commands ( known as bash script ), and through command, we can run this file in terminal. Let see how to run bash script in terminal. Example 1 : In this example we prin 2 min read 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 How to modify a string in JavaScript ? JavaScript strings are used for storing and manipulating text. It can contain zero or more characters within quotes and its indexing starts with 0. Strings are defined as an array of characters. In Javascript, we can also convert strings to a Character array. Representing a String: 1. Using double 3 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 - How to read a file line by line In this article, we are going to see how to read a file line by line in Bash scripting. There might be instances where you want to read the contents of a file line by line using a BASH script. In this section, we will look at different ways to do just that. We will use BASH commands and tools to ach 3 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 How To Run Bash Script In Linux? Bash scripts, also called shell scripts, are programs that help automate tasks by storing a series of commands that often go together, like updates or upgrades. These scripts make it easier to perform tasks automatically instead of typing each command manually. After creating a Bash script, you can 6 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 Bash Scripting - Case Statement A case statement in bash scripts is used when a decision has to be made against multiple choices. In other words, it is useful when an expression has the possibility to have multiple values. This methodology can be seen as a replacement for multiple if-statements in a script. Case statements have an 8 min read Like