<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>The Ops Community ⚙️: Tarush Arora</title>
    <description>The latest articles on The Ops Community ⚙️ by Tarush Arora (@whotarusharora).</description>
    <link>https://community.ops.io/whotarusharora</link>
    <image>
      <url>https://community.ops.io/images/_JV3Cchl5T3xr2J-jB_STpJjJ9TqWSjj6rMWMqbhdmA/rs:fill:90:90/g:sm/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL3Vz/ZXIvcHJvZmlsZV9p/bWFnZS8xNzkvOWEz/Mzc5NDAtYzQ5My00/NGE2LWEyY2QtZDBl/M2MxOTI4M2EyLmpw/Zw</url>
      <title>The Ops Community ⚙️: Tarush Arora</title>
      <link>https://community.ops.io/whotarusharora</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://community.ops.io/feed/whotarusharora"/>
    <language>en</language>
    <item>
      <title>How to Declare and Add Value in Bash Array: Continued</title>
      <dc:creator>Tarush Arora</dc:creator>
      <pubDate>Thu, 30 Jun 2022 17:40:22 +0000</pubDate>
      <link>https://community.ops.io/whotarusharora/how-to-declare-and-add-value-in-bash-array-continued-e97</link>
      <guid>https://community.ops.io/whotarusharora/how-to-declare-and-add-value-in-bash-array-continued-e97</guid>
      <description>&lt;p&gt;Further, array always stores the values in reference to index. Index can be defined as the position in the array. &lt;/p&gt;

&lt;p&gt;The first value you enter in the add command is stored with reference to the zero index, which is the first position in array.&lt;/p&gt;

&lt;p&gt;In Bash, you can also define the index, while adding the values. &lt;br&gt;
&lt;strong&gt;For Example:&lt;/strong&gt; Let’s add strings values, jan, feb, mar and apr in the my_array by defining the index. &lt;/p&gt;

&lt;p&gt;By executing the following command, all the string values will get stored in the my_array. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/VG5RCKROWK-Qc8jH17448iaku0UBTv8aW_af-kMTcAg/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2xyb2Mz/eWM4bDB5NjR1Z3h0/Mm9yLnBuZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/VG5RCKROWK-Qc8jH17448iaku0UBTv8aW_af-kMTcAg/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2xyb2Mz/eWM4bDB5NjR1Z3h0/Mm9yLnBuZw" alt="bash 1" width="649" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;jan will be stored in reference to zero index[0], feb to first index[1], mar to second[2] and apr to fourth[4].&lt;/p&gt;

&lt;p&gt;If you find it complex to add all the values at once, you can add them one by one, by running the below bash command. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/ylLRFtxmdLtfbHJua6qlelb46GirAs_zstuQupu6KUI/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2xzNDRi/cGVoeDE2ejN4OXA5/MWdvLnBuZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/ylLRFtxmdLtfbHJua6qlelb46GirAs_zstuQupu6KUI/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2xzNDRi/cGVoeDE2ejN4OXA5/MWdvLnBuZw" alt="bash 2" width="690" height="55"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You always have to put the value between the upper commas &lt;strong&gt;‘ ‘&lt;/strong&gt;. &lt;br&gt;
For associative arrays, bash offers an additional feature to have a string in the place of default index values. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Example:&lt;/strong&gt; If you want to add values in reference to index with string values instead of 0, 1, 2, etc., then you have to declare the associative array.&lt;/p&gt;

&lt;p&gt;In the following command, my_array is the associative array name and its first index value is &lt;strong&gt;[first]&lt;/strong&gt; instead of &lt;strong&gt;[0]&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/nrMomXhoMI3aA-LBE2OWqJXuqLvRYWgg5gZWXAOiHoo/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2E2dWp1/M3dkaTU0d241aHcx/YzFvLnBuZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/nrMomXhoMI3aA-LBE2OWqJXuqLvRYWgg5gZWXAOiHoo/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2E2dWp1/M3dkaTU0d241aHcx/YzFvLnBuZw" alt="bash 3" width="580" height="84"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can put any string in the place of [first], [second], and so on. &lt;/p&gt;

&lt;p&gt;For example: To create an array with index value of AAA, BBB and CCC, you will use the below commands:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;declare -A my_array&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;my_array[AAA]=’jan’&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;my_array[BBB]=’feb’&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;my_array[CCC]=’mar’&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In addition, you can also add all the values at once, by running the command according to below syntax. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/VXRD7whh2S9MhgMZBhU3sIph53kBMm_HO41GrMJIslA/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL3huMmZz/dTBjMnFsb3JwNmYw/emV0LnBuZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/VXRD7whh2S9MhgMZBhU3sIph53kBMm_HO41GrMJIslA/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL3huMmZz/dTBjMnFsb3JwNmYw/emV0LnBuZw" alt="bash 4" width="708" height="27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Besides the numeric and string index, you can add sequential values to a bash array by writing a single command. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Example:&lt;/strong&gt; For adding values from 1 to 6, you will run the command using &lt;strong&gt;seq&lt;/strong&gt; keyword. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/ACT1JPskPvXEuLjB7khtdWArCQW8ycZr7m8mXZb_75k/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzLzF0MmV2/d3BiamIxY2xwZmtm/anh1LnBuZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/ACT1JPskPvXEuLjB7khtdWArCQW8ycZr7m8mXZb_75k/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzLzF0MmV2/d3BiamIxY2xwZmtm/anh1LnBuZw" alt="bash 5" width="661" height="27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will store the values from 1 to 6 in the array, starting from the zero index [0]. &lt;/p&gt;

</description>
      <category>linux</category>
      <category>array</category>
      <category>basharray</category>
      <category>devops</category>
    </item>
    <item>
      <title>How to Declare and Add Value in Bash Array</title>
      <dc:creator>Tarush Arora</dc:creator>
      <pubDate>Thu, 02 Jun 2022 11:47:34 +0000</pubDate>
      <link>https://community.ops.io/whotarusharora/how-to-declare-and-add-value-in-bash-array-44le</link>
      <guid>https://community.ops.io/whotarusharora/how-to-declare-and-add-value-in-bash-array-44le</guid>
      <description>&lt;p&gt;&lt;a href="https://community.ops.io/images/enZhUW_Uz-QoEUUV-p388USbYu_72Xi-huEwFf32Qyc/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2I1amJ3/aGF0cHFwemltZTU3/NzB3LmpwZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/enZhUW_Uz-QoEUUV-p388USbYu_72Xi-huEwFf32Qyc/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2I1amJ3/aGF0cHFwemltZTU3/NzB3LmpwZw" alt="Head Image" width="259" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Declare Bash Array?
&lt;/h2&gt;

&lt;p&gt;By using the declare command, you can declare both indexed and associative array in the Bash. &lt;/p&gt;

&lt;p&gt;Let’s look at its syntax. &lt;/p&gt;

&lt;p&gt;For declaring the indexed array, you have to run the &lt;strong&gt;declare -a name_of_array&lt;/strong&gt; command.  &lt;/p&gt;

&lt;p&gt;Here, &lt;strong&gt;declare&lt;/strong&gt; is the keyword. &lt;br&gt;
&lt;strong&gt;-a&lt;/strong&gt; is option to create indexed array&lt;br&gt;
,and &lt;strong&gt;name_of_array&lt;/strong&gt; is the name of your array. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/yvcDM1ZriSyUTX_3CGOJsnU0uHOu28gRfhmJOzIHbbc/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2FoYTF2/bDJ3ZWk0Nmc4MnJ4/d2R0LnBuZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/yvcDM1ZriSyUTX_3CGOJsnU0uHOu28gRfhmJOzIHbbc/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2FoYTF2/bDJ3ZWk0Nmc4MnJ4/d2R0LnBuZw" alt="Declare" width="761" height="27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For Example: To declare an indexed array with name Linux, you have to use the following command: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;declare -a Linux&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can assign any name to the array, as per your requirement. &lt;br&gt;
However, it must have underscore sign, if there are multiple strings in the name. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Example:&lt;/strong&gt; To declare an array with name Linux my OS, you have to use the following command: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;declare -a Linux_my_OS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Further, for declaring the associative array, there’s only slight difference between the command. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;declare -A name_of_array&lt;/strong&gt; is the command for creating an associative array. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/ekz1Kc2f_HQGm9-CB43JwZKQXvDHGTB2SGt923TMdE4/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2d5NWpp/dzBxenFqbHB0dWk5/cW12LnBuZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/ekz1Kc2f_HQGm9-CB43JwZKQXvDHGTB2SGt923TMdE4/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2d5NWpp/dzBxenFqbHB0dWk5/cW12LnBuZw" alt="Declare -A" width="760" height="27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You only have to change the option from small a to capital A. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Example:&lt;/strong&gt; To declare an associative array with name Linux and Linux my OS, you will run the following command: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;declare -A Linux&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;declare -A Linux_my_OS&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Values in Bash Array
&lt;/h2&gt;

&lt;p&gt;Once you have declared the array, its time to store some values in it. &lt;/p&gt;

&lt;p&gt;Bash provides multiple ways to put values in the array and allows to add both numerical, alphabetical strings and combination of both in the array. &lt;/p&gt;

&lt;p&gt;Let’s have look at it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;my_array=(1 2 3 4)&lt;/strong&gt; command is used to add numerical value in the array with name my_array.  &lt;/p&gt;

&lt;p&gt;Once this command gets successfully executed, 1, 2, 3, and 4 gets stored in the array. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/ao4Vkq9q29Yl-r9YX7PlnypvjSAp6Ie_GKqhHoUOPOA/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2ViZG5l/MW8xdmd6bDMxcGR5/aDc5LnBuZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/ao4Vkq9q29Yl-r9YX7PlnypvjSAp6Ie_GKqhHoUOPOA/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL2ViZG5l/MW8xdmd6bDMxcGR5/aDc5LnBuZw" alt="Add 1" width="659" height="26"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can put any value of your choice. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Example:&lt;/strong&gt; To put values 10, 20, 30 and 40 in the array with name Linux, you will run the following command: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linux=(10 20 30 40)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To store string value in the array, you can follow the same command and write string value instead of numeric. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/XHmS8yTCGk-xgZtZeZmlDJxfWajDBIrvmOyUmUek0E0/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzLzZlMmFo/aXg1dXplYjYycGYy/dWdxLnBuZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/XHmS8yTCGk-xgZtZeZmlDJxfWajDBIrvmOyUmUek0E0/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzLzZlMmFo/aXg1dXplYjYycGYy/dWdxLnBuZw" alt="Add" width="731" height="27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Example:&lt;/strong&gt; To add string value Jan, Feb, Mar and April in the array with name Linux, you have to run the following command: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linux=(Jan Feb Mar April)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It will store the string values in your array. &lt;/p&gt;

&lt;h2&gt;
  
  
  To be Continued
&lt;/h2&gt;

</description>
      <category>linux</category>
      <category>basharray</category>
    </item>
    <item>
      <title>Introduction to Bash Arrays</title>
      <dc:creator>Tarush Arora</dc:creator>
      <pubDate>Mon, 30 May 2022 12:21:54 +0000</pubDate>
      <link>https://community.ops.io/whotarusharora/introduction-to-bash-arrays-cj</link>
      <guid>https://community.ops.io/whotarusharora/introduction-to-bash-arrays-cj</guid>
      <description>&lt;p&gt;&lt;a href="https://community.ops.io/images/KFPZbO1yC2EQkv01p1twSFapOyz5BADMTZI4714UL7w/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL28zMmJp/dTQ5OGM5Y3p4dG4w/b2o1LmpwZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/KFPZbO1yC2EQkv01p1twSFapOyz5BADMTZI4714UL7w/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL28zMmJp/dTQ5OGM5Y3p4dG4w/b2o1LmpwZw" alt="Cover Image" width="880" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bash scripts play an essential role in deploying cloud infrastructures, as most high-performing machines run on the Linux operating system.&lt;/p&gt;

&lt;p&gt;And bash arrays are always an essential part of every significant bash script.&lt;/p&gt;

&lt;p&gt;This article will teach the basics of bash arrays, starting from declaring them in Linux to passing them in a function.&lt;br&gt;
So, let’s get started and understand bash array.&lt;/p&gt;

&lt;p&gt;Bash Array is a one-dimensional data structure that helps store different values in an organized manner. Indexed and Associative are two of its types, which hold the integer and string values in reference to indices, known as index position or a key.&lt;/p&gt;

&lt;p&gt;You must have seen arrays in many programming languages, but bash arrays are pretty different.&lt;/p&gt;

&lt;p&gt;It allows the addition of different types of data types in a single array and can manage contrasting variables and provide accurate output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bash Array vs String
&lt;/h2&gt;

&lt;p&gt;In bash, you will find both arrays and strings.&lt;/p&gt;

&lt;p&gt;However, both are enormously different from each other. &lt;/p&gt;

&lt;p&gt;Where, array is a primary bash data structure, string is a data type, which you can store in an array. &lt;/p&gt;

&lt;p&gt;For Example: A string can be hello, windows, Linux, etc. Contrastingly, array is a data structure, which can hold a number of strings in it. &lt;br&gt;
You can declare an array and add strings into it, such as: &lt;br&gt;
&lt;strong&gt;declare -a my_array&lt;/strong&gt;                                         #command to create an array&lt;br&gt;
&lt;strong&gt;my_array=(hello windows Linux)&lt;/strong&gt;                 #command to store strings in an array&lt;/p&gt;

&lt;p&gt;Therefore, arrays are used to store strings. &lt;/p&gt;

&lt;h2&gt;
  
  
  Bash Array vs List
&lt;/h2&gt;

&lt;p&gt;Likewise, other programming languages, there are no lists in bash scripting. &lt;br&gt;
It only offers indexed and associative arrays for storing the variables and displaying them as list. &lt;br&gt;
Array uses index values for referencing the elements, leveraging to display stored variables in a list view. &lt;br&gt;
For Example: &lt;br&gt;
&lt;strong&gt;declare -a my_array&lt;/strong&gt;                            #creating array&lt;br&gt;
&lt;strong&gt;my_array=(one two three)&lt;/strong&gt;                #inserting elements into array&lt;br&gt;
&lt;strong&gt;echo ${my_array[@])&lt;/strong&gt;                          #displaying elements in a list view as per the array index&lt;br&gt;
&lt;strong&gt;Output:&lt;/strong&gt; &lt;br&gt;
one &lt;br&gt;
two &lt;br&gt;
three &lt;/p&gt;

</description>
      <category>tutorials</category>
      <category>productivity</category>
      <category>random</category>
    </item>
  </channel>
</rss>
