{"id":14617,"date":"2023-07-30T03:43:31","date_gmt":"2023-07-30T03:43:31","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=14617"},"modified":"2024-01-04T09:39:35","modified_gmt":"2024-01-04T09:39:35","slug":"variable-declaration-and-assignment","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/","title":{"rendered":"Variable Declaration and Assignment"},"content":{"rendered":"<p style=\"text-align: justify;\">In programming, a <strong>variable<\/strong> serves as a <strong>placeholder <\/strong>for an unknown value, enabling the user to store the different data and access them whenever needed. During <strong>compilation <\/strong>or <strong>interpretation<\/strong>, the symbolic names of variables are replaced with their corresponding <strong>data locations<\/strong>. This article will mainly focus on the <strong>variable declaration <\/strong>and <strong>assignment <\/strong>in a <strong>Bash Script<\/strong>. So, let\u2019s start.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#Key_Takeaways\" >Key Takeaways<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#Free_Downloads\" >Free Downloads<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#Factors_of_Variable_Declaration_and_Assignment\" >Factors of Variable Declaration and Assignment<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#1_Choosing_Appropriate_Variable_Name\" >1. Choosing Appropriate Variable Name<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#2_Declaring_the_Variable_in_the_Bash_Script\" >2. Declaring the Variable in the Bash Script<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#3_Assigning_the_Value_to_the_Variable\" >3. Assigning the Value to the Variable<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#4_Practical_Cases_of_Declaring_and_Assigning_Bash_Variable\" >4 Practical Cases of Declaring and Assigning Bash Variable<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#Case_01_Basic_Variable_Assignment_in_Bash_Script\" >Case 01: Basic Variable Assignment in Bash Script<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#Case_02_Input_From_User_and_Variable_Assignment\" >Case 02: Input From User and Variable Assignment<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#Case_03_Variable_Assignment_Using_Positional_Parameters\" >Case 03: Variable Assignment Using Positional Parameters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#Case_04_Environment_Variables_and_Variable_Scope\" >Case 04:\u00a0 Environment Variables and Variable Scope<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#People_Also_Ask\" >People Also Ask<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Key_Takeaways\"><\/span>Key Takeaways<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Getting familiar with Bash Variables.<\/li>\n<li>Learning to declare and assign variables.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Free_Downloads\"><\/span>Free Downloads<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"su-button-center\"><a href=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/Practice-files-Variable-Declaration-and-Assignment.zip\" class=\"su-button su-button-style-default\" style=\"color:#000000;background-color:#E8F9FF;border-color:#bac8cc;border-radius:56px\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"color:#000000;padding:8px 26px;font-size:20px;line-height:30px;border-color:#effbff;border-radius:56px;text-shadow:0px 0px 0px #000000\"><i class=\"sui sui-download\" style=\"font-size:20px;color:#1AA1D6\"><\/i> Download the Practice Files<\/span><\/a><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Factors_of_Variable_Declaration_and_Assignment\"><\/span>Factors of Variable Declaration and Assignment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">There are multiple factors to be followed to <strong>declare <\/strong>a <strong>variable <\/strong>and <strong>assign data <\/strong>to it. Here I have listed the factors below to understand the process. Check it out.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Choosing_Appropriate_Variable_Name\"><\/span>1. Choosing Appropriate Variable Name<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">When choosing appropriate variable names for declaration and assignment, it&#8217;s essential to follow some guidelines to ensure <strong>clarity<\/strong> and <strong>readability<\/strong> and to avoid conflicts with other system variables. Here some common guidelines to be followed are listed below:<\/p>\n<ul>\n<li><strong>Using descriptive names: <\/strong>Using descriptive names in variable naming conventions involves choosing meaningful and expressive names for variables in your code. This practice improves code readability and makes it easier to grasp the purpose of the code at a glance.<\/li>\n<li><strong>Using lowercase letters: <\/strong>It is a good practice to <strong>begin variable names<\/strong> with a <strong>lowercase letter<\/strong>. This convention is not enforced by the <strong>bash language <\/strong>itself, but it is a widely followed practice to improve <strong>code readability <\/strong>and <strong>maintain consistency<\/strong>. For example <strong>name<\/strong>, <strong>age<\/strong>, <strong>count<\/strong>, etc.<\/li>\n<li><strong>Separating words with underscores: <\/strong>Using underscores to separate words in variable names enhances code readability. For example <strong>first_name<\/strong>, <strong>num_students<\/strong>, etc.<\/li>\n<li><strong>Avoid starting with numbers: <\/strong>Variable names should not begin with a number. For instance, <strong>1var <\/strong>is <strong>not <\/strong>a <strong>valid variable <\/strong><\/li>\n<li><strong>Avoiding special characters<\/strong>: Avoid using <strong>special characters<\/strong>, <strong>whitespace<\/strong>, or <strong>punctuation <\/strong>marks, as they can cause syntax errors or introduce unexpected behavior. For instance, using any <strong>special character <\/strong>such as <strong>@, $, <\/strong>or <strong># <\/strong>anywhere while declaring a variable is not legal.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"2_Declaring_the_Variable_in_the_Bash_Script\"><\/span>2. Declaring the Variable in the Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In <strong>Bash<\/strong>, declaring variables and assigning values to them can be done for different data types by using different options along with the <a href=\"https:\/\/linuxsimply.com\/declare-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>declare command<\/strong><\/a>. However, you can also <strong>declare <\/strong>and <strong>assign <\/strong>the variable value <strong>without explicitly specifying the type<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Assigning_the_Value_to_the_Variable\"><\/span>3. Assigning the Value to the Variable<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">When declaring variables for <strong>numeric values<\/strong>, simply assign the desired number directly, as in <strong>age=30<\/strong> for an <strong>integer <\/strong>or <strong>price=12.99<\/strong> for a <strong>floating<\/strong>&#8211;<strong>point<\/strong> <strong>value<\/strong>. For <strong>strings<\/strong>, enclose the text in <strong>single <\/strong>or <strong>double quotes<\/strong>, such as <strong>name<\/strong>=&#8217;<strong>John<\/strong>&#8216; or<strong> city<\/strong>=&#8221;<strong>New York<\/strong>&#8220;. <strong>Booleans <\/strong>can be represented using<strong> 0<\/strong> and <strong>1<\/strong>, where <strong>0 <\/strong>indicates <strong>false <\/strong>and<strong> 1 <\/strong>represents <strong>true<\/strong>, like <strong>is_valid<\/strong>=<strong>1<\/strong>.<\/p>\n<p style=\"text-align: justify;\"><div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e8f9fc;border-color:#ffffff;color:#333333;\"><strong>Note:<\/strong> In Bash scripting, <strong>single quotes <\/strong>(&#8216; &#8216;) and <strong>double quotes <\/strong>(&#8221; &#8220;) are used to define strings, but they behave differently in certain situations. For instance, in the case of <strong>double quotes<\/strong>, if you have a <strong>variable $name<\/strong>, it will be replaced with its value inside the double-quoted string. Whereas variables within <strong>single quotes <\/strong>are treated literally as normal strings. They won&#8217;t be expanded, and the variable names will be included as-is in the string. <\/div><\/div>\n<p><strong>Arrays <\/strong>are declared by assigning a sequence of values enclosed in parentheses to a variable, e.g., <strong>fruits=(&#8220;apple&#8221; &#8220;banana&#8221; &#8220;orange&#8221;)<\/strong>. To create <strong>associative arrays <\/strong>(<strong>key-value pairs<\/strong>), use the <strong>declare -A command <\/strong>followed by assigning the elements, like <strong>declare -A ages=([&#8220;John&#8221;]=30 [&#8220;Jane&#8221;]=25)<\/strong>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"4_Practical_Cases_of_Declaring_and_Assigning_Bash_Variable\"><\/span>4 Practical Cases of Declaring and Assigning Bash Variable<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In this section, I have demonstrated some sample <strong>Bash scripts <\/strong>that will help you understand the basic concept of <strong>variable declaration <\/strong>and <strong>assignment <\/strong>in <strong>Bash script<\/strong>. So let\u2019s get into it.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Case_01_Basic_Variable_Assignment_in_Bash_Script\"><\/span>Case 01: Basic Variable Assignment in Bash Script<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In my <strong>first case<\/strong>, I have shown a basic variable assignment with its output. Here, I have taken a <strong>string<\/strong> and an <strong>integer variable <\/strong>to show the basic variable assignment mechanism. Follow the given steps to accomplish the task.<\/p>\n<p><span style=\"color: #800080;\"><strong><a id=\"anchor1\"><\/a>Steps to Follow &gt;<\/strong><\/span><\/p>\n<p>\u2776 At first, launch an <strong>Ubuntu <\/strong><a href=\"https:\/\/linuxsimply.com\/what-is-terminal-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>terminal<\/strong><\/a>.<\/p>\n<p>\u2777 Write the following command to open a file in <strong>Nano<\/strong>:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">nano basic_var.sh<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<ul>\n<li><a href=\"https:\/\/linuxsimply.com\/nano-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>nano<\/strong><\/a><strong>:<\/strong> Opens a file in the <strong>Nano <\/strong>text editor.<\/li>\n<li><strong>basic_var.sh<\/strong>: Name of the file.<\/li>\n<\/ul>\n<\/div><\/div>\n<p>\u2778 Copy the script mentioned below:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n# Variable Declaration and Assignment\nname=&quot;John&quot;\nage=30\n\n# Printing the variables\necho &quot;Name: $name&quot;\necho &quot;Age: $age&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The script starts with the <strong>shebang <\/strong>line (<strong>#!\/bin\/bash<\/strong>), specifying that the script should be executed using the <strong>Bash shell<\/strong>. Next, <strong>two variables <\/strong>are declared and assigned values using the format <strong>variable_name<\/strong>=<strong>value<\/strong>. The first variable is <strong>name<\/strong>, and it is assigned the <strong>string <\/strong>value &#8220;<strong>John<\/strong>.&#8221; The second variable is <strong>age<\/strong>, assigned the numeric value <strong>30<\/strong>. The script then uses the <a href=\"https:\/\/linuxsimply.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>echo command<\/strong><\/a> to print the values of the variables.<\/p>\n<\/div><\/div>\n<p>\u2779 Press <strong>CTRL+O<\/strong> and <strong>ENTER <\/strong>to save the file; <strong>CTRL+X<\/strong> to exit.<\/p>\n<p>\u277a Use the following command to make the file executable:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">chmod u+x basic_var.sh<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<ul>\n<li><a href=\"https:\/\/linuxsimply.com\/chmod-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>chmod<\/strong><\/a>: is used to change the permissions of files and directories.<\/li>\n<li style=\"text-align: justify;\"><strong>u+x<\/strong>: Here, <strong>u<\/strong> refers to the &#8220;<strong>user<\/strong>&#8221; or the <strong>owner <\/strong>of the file and <strong>+x<\/strong> specifies the permission being added, in this case, the &#8220;<strong>execute<\/strong>&#8221; permission. When <strong>u+x<\/strong> is added to the file permissions, it grants the user (<strong>owner<\/strong>) permission to execute (<strong>run<\/strong>) the file.<\/li>\n<li><strong>basic_var.sh<\/strong>: File name to which the permissions are being applied.<\/li>\n<\/ul>\n<\/div><\/div>\n<p>\u277b Run the script by the following command:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/basic_var.sh<\/code><\/pre>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-14620 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/1.-Basic-Variable-Assignment-in-Bash-Script.png\" alt=\"Basic Variable Assignment in Bash Script\" width=\"609\" height=\"185\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/1.-Basic-Variable-Assignment-in-Bash-Script.png 609w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/1.-Basic-Variable-Assignment-in-Bash-Script-300x91.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/1.-Basic-Variable-Assignment-in-Bash-Script-767x233.png 767w\" sizes=\"(max-width: 609px) 100vw, 609px\" \/>Upon executing the script, the output displays the content of the variables: <strong>Name: John<\/strong> and <strong>Age: 30<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Case_02_Input_From_User_and_Variable_Assignment\"><\/span>Case 02: Input From User and Variable Assignment<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In <strong>Bash<\/strong>, you can take input from the <strong>user <\/strong>and <strong>store <\/strong>it in variables using the <strong>read command<\/strong>. To do so use the following script:<\/p>\n<div class=\"su-note\"  style=\"border-color:#e5e5e5;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#ffffff;border-color:#ffffff;color:#333333;\">\n<p>You can follow the <a href=\"#anchor1\"><strong>steps of Case 01<\/strong><\/a>, to create, save and make the script executable.<\/p>\n<\/div><\/div>\n<p><span style=\"color: #800080;\"><strong>Script (user_var.sh) &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n# Prompt the user for input\nread -p &quot;Enter your name: &quot; name\nread -p &quot;Enter your age: &quot; age\n\n# Printing the variables\necho &quot;Name: $name&quot;\necho &quot;Age: $age&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The script starts with the <strong>shebang line <\/strong>(<strong>#!\/bin\/bash<\/strong>) to specify that the <strong>Bash shell <\/strong>should be used for executing the script. The <strong>read command <\/strong>is then used twice, each with the <strong>-p<\/strong> option, to prompt the user for input. Both the <strong>name <\/strong>and <strong>age variables <\/strong>take the name and age of the user and store them in the <strong>name <\/strong>and<strong> age variable <\/strong>with the help of the <strong>read command<\/strong>. Then the script uses the <strong>echo command <\/strong>to print the values of the <strong>variable&#8217;s name <\/strong>and <strong>age<\/strong>, respectively. The $<strong>name<\/strong> and <strong>$age<\/strong> <strong>syntax <\/strong>are used to access the values stored in the variables and display them in the output.<\/p>\n<\/div><\/div>\n<p>Now, run the following command into your terminal to execute the bash file.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/user_var.sh<\/code><\/pre>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-14621 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/2.-Input-from-User-and-Variable-Assignment.png\" alt=\"Input from User and Variable Assignment\" width=\"605\" height=\"219\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/2.-Input-from-User-and-Variable-Assignment.png 605w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/2.-Input-from-User-and-Variable-Assignment-300x109.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/2.-Input-from-User-and-Variable-Assignment-768x278.png 768w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/>When you run the script, it will ask you to enter your <strong>name <\/strong>and <strong>age<\/strong>. Upon providing the input <strong>Jhon <\/strong>and <strong>30<\/strong>, the script prints<strong> Name: John<\/strong> and <strong>Age: 30 <\/strong>in the terminal.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Case_03_Variable_Assignment_Using_Positional_Parameters\"><\/span>Case 03: Variable Assignment Using Positional Parameters<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In <strong>Bash<\/strong>, you can assign values to variables using <strong>positional parameters<\/strong>. <strong>Positional parameters <\/strong>are <strong>special variables <\/strong>that hold arguments passed to the script when it is executed. They are referenced by their position, starting from <strong>$0<\/strong> for the script name,<strong> $1<\/strong> for the <strong>first argument<\/strong>, <strong>$2<\/strong> for the <strong>second argument<\/strong>, and so on. To do the same use the below script.<\/p>\n<div class=\"su-note\"  style=\"border-color:#e5e5e5;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#ffffff;border-color:#ffffff;color:#333333;\">\n<p>You can follow the <a href=\"#anchor1\"><strong>steps of Case 01<\/strong><\/a>, to create, save and make the script executable.<\/p>\n<\/div><\/div>\n<p><span style=\"color: #800080;\"><strong>Script (var_command_line.sh) &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n# Prompt the user for input\nname=$1\nage=$2\n\n# Printing the variables\necho &quot;Name: $name&quot;\necho &quot;Age: $age&quot;<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The script starts with the <strong>shebang line <\/strong>(<strong>#!\/bin\/bash<\/strong>) to specify that the <strong>Bash shell <\/strong>should be used for executing the script. The script uses the special variables <strong>$1<\/strong> and $2, which represent the <strong>first <\/strong>and <strong>second command<\/strong>&#8211;<strong>line<\/strong> <strong>arguments<\/strong>, respectively, and assigns their values to the <strong>name <\/strong>and <strong>age variables<\/strong>. The $<strong>name<\/strong> and <strong>$age<\/strong> <strong>syntax <\/strong>are used to access the values stored in the variables and display them using the <strong>echo command<\/strong>.<\/p>\n<\/div><\/div>\n<p>Now, run the following command into your terminal to execute the script.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/var_command_line.sh John 30<\/code><\/pre>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-14622 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/3.-Variable-Assignment-Using-Positional-Parameters.png\" alt=\"Variable Assignment Using Positional Parameters\" width=\"667\" height=\"162\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/3.-Variable-Assignment-Using-Positional-Parameters.png 667w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/3.-Variable-Assignment-Using-Positional-Parameters-300x73.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/3.-Variable-Assignment-Using-Positional-Parameters-766x186.png 766w\" sizes=\"(max-width: 667px) 100vw, 667px\" \/><\/p>\n<p>Upon execution of the <strong>Bash<\/strong> <strong>file<\/strong>, the script takes two command-line arguments, <strong>John<\/strong> and <strong>30<\/strong>, and returns the output <strong>Name<\/strong>: <strong>John<\/strong> and <strong>Age<\/strong>: <strong>30<\/strong> in the command line.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Case_04_Environment_Variables_and_Variable_Scope\"><\/span>Case 04:\u00a0 Environment Variables and Variable Scope<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">In <strong>Bash script<\/strong>, <strong>Environment Variables <\/strong>are another type of variable. Those variables are available in the <strong>current session <\/strong>and its <strong>child processes <\/strong>once you export your own variable in the environment. However, you can access those and scope it to a function. Here&#8217;s a sample Bash script code of environment variables and variable scope describing the concept.<\/p>\n<div class=\"su-note\"  style=\"border-color:#e5e5e5;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#ffffff;border-color:#ffffff;color:#333333;\">\n<p>You can follow the <a href=\"#anchor1\"><strong>steps of Case 01<\/strong><\/a>, to create, save and make the script executable.<\/p>\n<\/div><\/div>\n<p><span style=\"color: #800080;\"><strong>Script (var_scope.sh) &gt;<\/strong><\/span><\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n# Environment variable assignment\nexport MY_VARIABLE=&quot;Hello, World!&quot;\n\n# Function with a local variable\n\nmy_function() {\n\u00a0 local local_var=&quot;I am a local variable&quot;\n\u00a0 echo &quot;Function Output: $local_var&quot;\n}\n\n# Printing the environment variable and calling the function\necho &quot;Environment Variable: $MY_VARIABLE&quot;\nmy_function<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#E1E3E6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\"> EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">The script starts with the <strong>shebang line <\/strong>(<strong>#!\/bin\/bash<\/strong>) to specify that the <strong>Bash shell <\/strong>should be used for executing the script. Then, an environment variable named <strong>MY_VARIABLE <\/strong>is assigned the value &#8220;<strong>Hello, World!<\/strong>&#8221; using the <strong>export command<\/strong>. The script also defines a <strong>Bash function <\/strong>called <strong>my_function<\/strong>. Inside this function, a local variable named <strong>local_var <\/strong>is declared using the <strong>local keyword<\/strong>. After defining the function, the script proceeds to print the value of the environment variable <strong>MY_VARIABLE<\/strong>, which is accessible throughout the script. Upon calling the <strong>my_function<\/strong>, it prints the value of the <strong>local variable local_var<\/strong>, demonstrating its <strong>local scope<\/strong>.<\/p>\n<\/div><\/div>\n<p>Finally, run the following command into your terminal to execute the bash file.<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">.\/var_scope.sh<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-14618 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/4.-Environment-Variables-and-Variable-Scope.png\" alt=\"Environment Variables and Variable Scope\" width=\"627\" height=\"172\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/4.-Environment-Variables-and-Variable-Scope.png 627w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/4.-Environment-Variables-and-Variable-Scope-300x82.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/4.-Environment-Variables-and-Variable-Scope-766x210.png 766w\" sizes=\"(max-width: 627px) 100vw, 627px\" \/><\/p>\n<p>Upon printing the <strong>My_VARIABLE <\/strong>and calling the <strong>my_function,<\/strong> the code returns \u201c<strong>Environment Variable: Hello, World<\/strong>\u201d and &#8220;<strong>I am a local variable<\/strong>&#8221; respectively.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In conclusion, <strong>variable declaration and assignment <\/strong>is a very straightforward process and does not take any extra effort to declare the variable first, just like the <strong>Python programming language<\/strong>. In this article, I have tried to give you a guideline on how to declare and assign variables in a <strong>Bash Scripts<\/strong>. I have also provided some practical cases related to this topic. However, if you have any questions or queries regarding this article, feel free to comment below. I will get back to you soon. Thank You!<\/p>\n<h2><span class=\"ez-toc-section\" id=\"People_Also_Ask\"><\/span>People Also Ask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"su-accordion su-u-trim\">\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>What is variable declaration and assignment?<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> <strong>Variable declaration <\/strong>is the act of introducing a new variable to the program by specifying its name and type. As far as the <strong>Bash Script <\/strong>is concerned, the variable type does not need to <strong>declare explicitly<\/strong>.<\/div><\/div>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>What is used to assign a variable?<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> The <strong>equals sign<\/strong> <strong>(=) <\/strong>is for variable assignment in programming, like<strong> x = 5<\/strong>; where the <strong>variable x<\/strong> is assigned the value <strong>5<\/strong>. <\/div><\/div>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>What is the difference between assignment statement and variable?<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> The assignment statement is a programming construct used to give a <strong>value <\/strong>to a <strong>variable<\/strong>. It involves using the equal sign &#8220;<strong>=<\/strong>&#8221; to assign a specific value or expression to a variable. On the other hand, a <strong>variable <\/strong>is a named storage location in the computer&#8217;s memory that holds a value. It acts as a <strong>placeholder for data <\/strong>and can be referenced by its name throughout the program.<\/div><\/div>\n<div class=\"su-spoiler su-spoiler-style-fancy su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>How do you declare and assign variables?<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\"> In <strong>Bash<\/strong>, you can <strong>declare <\/strong>and <strong>assign <\/strong>variables in a single line <strong>without explicitly specifying the data type<\/strong>. For example, to <strong>declare <\/strong>and <strong>assign <\/strong>the variable name with the value &#8220;<strong>John<\/strong>&#8221; you would write: <strong>name=&#8221;John&#8221;<\/strong>.<\/div><\/div>\n<\/div>\n<p><span style=\"font-size: 18pt; color: #003366;\"><strong>Related Articles<\/strong><\/span><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/declare-variable\/\" target=\"_blank\" rel=\"noopener\">How to Declare Variable in Bash Scripts? [5 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/naming-convention\/\" target=\"_blank\" rel=\"noopener\">Bash Variable Naming Conventions in Shell Script [6 Rules]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/assign-variable\/\" target=\"_blank\" rel=\"noopener\">How to Assign Variables in Bash Script? [8 Practical Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/check-value\/\" target=\"_blank\" rel=\"noopener\">How to Check Variable Value Using Bash Scripts? [5 Cases]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/default-value\/\" target=\"_blank\" rel=\"noopener\">How to Use Default Value in Bash Scripts? [2 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/set-variable\/\" target=\"_blank\" rel=\"noopener\">How to Use Set \u2013 $Variable in Bash Scripts? [2 Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/read-environment-variables\/\" target=\"_blank\" rel=\"noopener\">How to Read Environment Variables in Bash Script? [2 Methods]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/export-in-bash\/\" target=\"_blank\" rel=\"noopener\">How to Export Environment Variables with Bash? [4 Examples]<\/a><\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>&lt;&lt; Go Back to <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Bash Variable&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:16768,&quot;10&quot;:1,&quot;11&quot;:4,&quot;17&quot;:1}\" data-sheets-hyperlink=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/\"><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/\" target=\"_blank\" rel=\"noopener\">Bash Variables<\/a><\/span> | <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/\" target=\"_blank\" rel=\"noopener\">Bash Scripting Tutorial<\/a><\/strong><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;14617&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Variable Declaration and Assignment&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\">Rate this post<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>In programming, a variable serves as a placeholder for an unknown value, enabling the user to store the different data &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Variable Declaration and Assignment\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#more-14617\" aria-label=\"Read more about Variable Declaration and Assignment\">Read more<\/a><\/p>\n","protected":false},"author":314906,"featured_media":14623,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102],"tags":[127],"class_list":["post-14617","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-scripting","tag-bash-variables","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Variable Declaration and Assignment - LinuxSimply<\/title>\n<meta name=\"description\" content=\"Variable declaration assignment is a process to contain data for manipulation in programming, enabling dynamic and adaptable code creation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Variable Declaration and Assignment - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"Variable declaration assignment is a process to contain data for manipulation in programming, enabling dynamic and adaptable code creation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/msmshah.miran\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-30T03:43:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-04T09:39:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/Variable-Declaration-and-Assignment.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Mohammad Shah Miran\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mohammad Shah Miran\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/\"},\"author\":{\"name\":\"Mohammad Shah Miran\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/3d367dace727c53f2b8683eeb23fae77\"},\"headline\":\"Variable Declaration and Assignment\",\"datePublished\":\"2023-07-30T03:43:31+00:00\",\"dateModified\":\"2024-01-04T09:39:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/\"},\"wordCount\":2041,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/Variable-Declaration-and-Assignment.png\",\"keywords\":[\"bash variables\"],\"articleSection\":[\"Bash Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/\",\"name\":\"Variable Declaration and Assignment - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/Variable-Declaration-and-Assignment.png\",\"datePublished\":\"2023-07-30T03:43:31+00:00\",\"dateModified\":\"2024-01-04T09:39:35+00:00\",\"description\":\"Variable declaration assignment is a process to contain data for manipulation in programming, enabling dynamic and adaptable code creation.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/Variable-Declaration-and-Assignment.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/Variable-Declaration-and-Assignment.png\",\"width\":400,\"height\":400,\"caption\":\"Variable Declaration and Assignment\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/declaration-and-assignment\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Scripting Tutorial\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bash Variables\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/bash-scripting-tutorial\\\/variables\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Variable Declaration and Assignment\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"name\":\"LinuxSimply\",\"description\":\"All About Linux\",\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxsimply.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\",\"name\":\"LinuxSimply\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"width\":355,\"height\":48,\"caption\":\"LinuxSimply\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/3d367dace727c53f2b8683eeb23fae77\",\"name\":\"Mohammad Shah Miran\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Mohammad-Shah-Miran-II-96x96.png\",\"caption\":\"Mohammad Shah Miran\"},\"description\":\"Hey, I'm Mohammad Shah Miran, previously worked as a VBA and Excel Content Developer at SOFTEKO, and for now working as a Linux Content Developer Executive in LinuxSimply Project. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). As a part of my job, i communicate with Linux operating system, without letting the GUI to intervene and try to pass it to our audience.\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/msmshah.miran\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/shah-miran-2a94a7144\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/miran\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Variable Declaration and Assignment - LinuxSimply","description":"Variable declaration assignment is a process to contain data for manipulation in programming, enabling dynamic and adaptable code creation.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/","og_locale":"en_US","og_type":"article","og_title":"Variable Declaration and Assignment - LinuxSimply","og_description":"Variable declaration assignment is a process to contain data for manipulation in programming, enabling dynamic and adaptable code creation.","og_url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/msmshah.miran\/","article_published_time":"2023-07-30T03:43:31+00:00","article_modified_time":"2024-01-04T09:39:35+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/Variable-Declaration-and-Assignment.png","type":"image\/png"}],"author":"Mohammad Shah Miran","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mohammad Shah Miran","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/"},"author":{"name":"Mohammad Shah Miran","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/3d367dace727c53f2b8683eeb23fae77"},"headline":"Variable Declaration and Assignment","datePublished":"2023-07-30T03:43:31+00:00","dateModified":"2024-01-04T09:39:35+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/"},"wordCount":2041,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/Variable-Declaration-and-Assignment.png","keywords":["bash variables"],"articleSection":["Bash Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/","url":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/","name":"Variable Declaration and Assignment - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/Variable-Declaration-and-Assignment.png","datePublished":"2023-07-30T03:43:31+00:00","dateModified":"2024-01-04T09:39:35+00:00","description":"Variable declaration assignment is a process to contain data for manipulation in programming, enabling dynamic and adaptable code creation.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/Variable-Declaration-and-Assignment.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/07\/Variable-Declaration-and-Assignment.png","width":400,"height":400,"caption":"Variable Declaration and Assignment"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/declaration-and-assignment\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxsimply.com\/"},{"@type":"ListItem","position":2,"name":"Bash Scripting Tutorial","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/"},{"@type":"ListItem","position":3,"name":"Bash Variables","item":"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/"},{"@type":"ListItem","position":4,"name":"Variable Declaration and Assignment"}]},{"@type":"WebSite","@id":"https:\/\/linuxsimply.com\/#website","url":"https:\/\/linuxsimply.com\/","name":"LinuxSimply","description":"All About Linux","publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxsimply.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxsimply.com\/#organization","name":"LinuxSimply","url":"https:\/\/linuxsimply.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","width":355,"height":48,"caption":"LinuxSimply"},"image":{"@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/3d367dace727c53f2b8683eeb23fae77","name":"Mohammad Shah Miran","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/Mohammad-Shah-Miran-II-96x96.png","caption":"Mohammad Shah Miran"},"description":"Hey, I'm Mohammad Shah Miran, previously worked as a VBA and Excel Content Developer at SOFTEKO, and for now working as a Linux Content Developer Executive in LinuxSimply Project. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). As a part of my job, i communicate with Linux operating system, without letting the GUI to intervene and try to pass it to our audience.","sameAs":["https:\/\/www.facebook.com\/msmshah.miran\/","https:\/\/www.linkedin.com\/in\/shah-miran-2a94a7144\/"],"url":"https:\/\/linuxsimply.com\/author\/miran\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/14617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/users\/314906"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=14617"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/14617\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/14623"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=14617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=14617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=14617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}