<?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>DEV Community: Sourin🥑 | Web 3.0 &amp; Blockchain🚀</title>
    <description>The latest articles on DEV Community by Sourin🥑 | Web 3.0 &amp; Blockchain🚀 (@heysourin).</description>
    <link>https://dev.to/heysourin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1071567%2F34774d27-344f-4291-b67f-af83fd1f4888.jpg</url>
      <title>DEV Community: Sourin🥑 | Web 3.0 &amp; Blockchain🚀</title>
      <link>https://dev.to/heysourin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/heysourin"/>
    <language>en</language>
    <item>
      <title>Complete Shell Scripting Guidance</title>
      <dc:creator>Sourin🥑 | Web 3.0 &amp; Blockchain🚀</dc:creator>
      <pubDate>Sat, 02 Sep 2023 05:25:06 +0000</pubDate>
      <link>https://dev.to/heysourin/complete-shell-scripting-guidance-1pf8</link>
      <guid>https://dev.to/heysourin/complete-shell-scripting-guidance-1pf8</guid>
      <description>&lt;h2&gt;
  
  
  Shell Scripting Tutorial
&lt;/h2&gt;

&lt;p&gt;Welcome to the Shell Scripting Tutorial repository! In this tutorial, you'll learn the fundamentals of shell scripting, a powerful skill for automating tasks, managing systems, and more. Whether you're a beginner or have some programming experience, this guide will help you understand the basics of shell scripting.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All source codes: &lt;a href="https://github.com/heysourin/Shell-Scripting" rel="noopener noreferrer"&gt;https://github.com/heysourin/Shell-Scripting&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Video Reference (In Hindi): &lt;a href="https://www.youtube.com/watch?v=TtGM9GfBuok&amp;amp;t=13429s" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=TtGM9GfBuok&amp;amp;t=13429s&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What is a Shell?&lt;/li&gt;
&lt;li&gt;Different Types of Shells&lt;/li&gt;
&lt;li&gt;What is Shell Scripting?&lt;/li&gt;
&lt;li&gt;Key characteristics and functions of a shell include&lt;/li&gt;
&lt;li&gt;Shebang&lt;/li&gt;
&lt;li&gt;Output in the Terminal&lt;/li&gt;
&lt;li&gt;How to Create a Shell File?&lt;/li&gt;
&lt;li&gt;How to Save the File from Editor?&lt;/li&gt;
&lt;li&gt;How to Run Shell Scripts?&lt;/li&gt;
&lt;li&gt;Comments&lt;/li&gt;
&lt;li&gt;Variables&lt;/li&gt;
&lt;li&gt;Array&lt;/li&gt;
&lt;li&gt;User Input&lt;/li&gt;
&lt;li&gt;Arithmetic operatings&lt;/li&gt;
&lt;li&gt;
Conditionals

&lt;ul&gt;
&lt;li&gt;if-else&lt;/li&gt;
&lt;li&gt;elif&lt;/li&gt;
&lt;li&gt;choice&lt;/li&gt;
&lt;li&gt;Logical Operators&lt;/li&gt;
&lt;li&gt;Ternary Operator&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Loops

&lt;ul&gt;
&lt;li&gt;for loop&lt;/li&gt;
&lt;li&gt;for loop Iteration on Files&lt;/li&gt;
&lt;li&gt;for loop on an Array&lt;/li&gt;
&lt;li&gt;while loop&lt;/li&gt;
&lt;li&gt;until loops&lt;/li&gt;
&lt;li&gt;Infinite loop using while loop&lt;/li&gt;
&lt;li&gt;Infinite loop using for loop&lt;/li&gt;
&lt;li&gt;Reading a File using While Loop&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Functions

&lt;ul&gt;
&lt;li&gt;Function with Arguments&lt;/li&gt;
&lt;li&gt;Arguments passing directly on the shell&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Break, Continue, and Sleep

&lt;ul&gt;
&lt;li&gt;Break&lt;/li&gt;
&lt;li&gt;Continue&lt;/li&gt;
&lt;li&gt;Sleep, Exit, and &lt;code&gt;$?&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Connectivity Check&lt;/li&gt;
&lt;li&gt;
Checking if a File and Directory Exist

&lt;ul&gt;
&lt;li&gt;Directory&lt;/li&gt;
&lt;li&gt;File&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Bash Variables&lt;/li&gt;
&lt;li&gt;Login as Root User&lt;/li&gt;
&lt;li&gt;Redirection&lt;/li&gt;
&lt;li&gt;Log Messages&lt;/li&gt;
&lt;li&gt;Debugging&lt;/li&gt;
&lt;li&gt;Running a File in the Background&lt;/li&gt;
&lt;li&gt;Automation&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What is a Shell?
&lt;/h2&gt;

&lt;p&gt;A shell is a command-line interface (CLI) program that provides a user-friendly way to interact with an operating system (OS) or a computer system. It serves as a bridge between the user and the kernel (core of OS) by interpreting and executing commands entered by the user or by scripts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fheysourin%2FShell-Scripting%2Fassets%2F98945276%2F1713e770-23bd-4653-806e-4ed44de07ac9" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fheysourin%2FShell-Scripting%2Fassets%2F98945276%2F1713e770-23bd-4653-806e-4ed44de07ac9"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Different Types of Shells
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Bash (Bourne-Again Shell): Bash is one of the most widely used shells and is the default shell on many Linux distributions. It is a powerful and versatile shell that supports scripting, interactive use, and command-line automation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Zsh (Z Shell): Zsh is known for its extensive customization options and interactive features. It offers advanced auto-completion, syntax highlighting, and theming. Many users prefer Zsh for its user-friendly experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fish (Friendly Interactive Shell): Fish is designed to be a user-friendly shell with a focus on interactive use. It provides helpful features like auto-suggestions, syntax highlighting, and an easy-to-understand scripting syntax.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dash: Dash is a minimalistic POSIX-compliant shell optimized for scripting. It is often used as the default /bin/sh shell on many Unix systems because of its speed and efficiency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tcsh: Tcsh is an enhanced version of the C shell (csh) with additional features like command-line history, command-line editing, and job control. It's popular among some Unix users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ksh (Korn Shell): The Korn Shell is known for its scripting capabilities and is compatible with the Bourne Shell (sh). It offers advanced scripting features like associative arrays and floating-point arithmetic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ash (Almquist Shell): Ash is a lightweight and efficient shell that adheres to the POSIX shell standard. It is often used in embedded systems and as the basis for other shells like Dash.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Csh (C Shell): The C shell is an early Unix shell with C-like syntax. It offers some unique features but is less commonly used today, especially for scripting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PowerShell: While primarily associated with Microsoft Windows, PowerShell has also been developed for Linux and macOS. It is a powerful and object-oriented shell designed for automation and system administration.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;etc&lt;/p&gt;

&lt;h2&gt;
  
  
  What is shell scripting?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Shell scripting is a way to automate tasks and create programs using shell commands. A shell script is a sequence of commands that can be executed in a shell environment. Shell scripts are commonly used for system administration, automation, and other tasks.&lt;/li&gt;
&lt;li&gt;All the commands execute sequentially.&lt;/li&gt;
&lt;li&gt;Some important tasks engineers do with shell scripting is file manipulation, program execution, user interaction, automation etc.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key characteristics and functions of a shell include
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Command Interpretation: The shell interprets commands entered by the user and translates them into instructions that the operating system can understand and execute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Command Execution: It runs programs, utilities, and scripts on behalf of the user. This includes both built-in shell commands and external programs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scripting: Shells support scripting languages that allow users to automate tasks by writing sequences of commands in script files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I/O Redirection: Shells allow users to redirect input and output streams (e.g., redirecting output to a file) to manipulate and process data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Variables: Users can create and manipulate variables to store and retrieve data within the shell environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Control Structures: Shells support conditional statements (e.g., if-else), loops (e.g., for, while), and other control structures for scripting and automation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Environment Management: Shells manage environment variables, which are used to store configuration information and data that can be accessed by programs and scripts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Customization: Users can customize their shell environment by defining aliases, setting prompts, and configuring various settings.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Shebang
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A shebang, also known as a hashbang or pound-bang, is a special character sequence at the very beginning of a text file. It is used in Unix-like operating systems to specify the interpreter that should be used to execute the script or program contained in the file.&lt;/li&gt;
&lt;li&gt;Whenever we try to execute a script, we have to instruct the Linux machine which interpreter or shell it should be using. It is possible that, in some machines 'bash' is not the default shell.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In this case, it indicates that the script should be executing using bash shell.&lt;/li&gt;
&lt;li&gt;It is not mandatory, but it is a good practice.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Output in the Terminal
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"hello world"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;echo "hello world":&lt;/code&gt; This is the main command of the script. It uses the echo command to print the text "hello world" to the standard output (usually the terminal or console).&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create a Shell File?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;touch fileName.sh&lt;/code&gt; then &lt;code&gt;vi fileName.sh&lt;/code&gt;: It will create a file then open 'vi' editor on the shell where you can edit and create your shell scripts.&lt;/li&gt;
&lt;li&gt;Or you can directly do &lt;code&gt;vi fileName.sh&lt;/code&gt; it will do the samen, create the file and open it on the editor.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to save the file from editor?
&lt;/h2&gt;

&lt;p&gt;Whenever you finish writing the script, you press &lt;code&gt;esc&lt;/code&gt; button then type &lt;code&gt;:wq&lt;/code&gt;. It will save changes and quit the editor.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run Shell Scripts?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;bash fileName.sh&lt;/code&gt; will allow you to run the script. Make sure your file is in the same directory that you are currently in (on your shell) or you provide proper path-directory before the file-name&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PS. Below I am going to teach Shell Scripting. You will have to save easch file and run with the command I mentioned above.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Comments
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Before comments"&lt;/span&gt;

&lt;span class="c"&gt;#Single line comment&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;comment&lt;/span&gt;&lt;span class="sh"&gt;
This 
is 
a 
multi
line 
comments

&lt;/span&gt;&lt;span class="no"&gt;comment

&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"After comments"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;#: The hash symbol (#)&lt;/code&gt; at the beginning of the line is used to indicate a single-line comment in Bash. Any text following the # on the same line is considered a comment and is not executed as code.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;&amp;lt;comment&lt;/code&gt; at the beginning and &lt;code&gt;comment&lt;/code&gt; at the end of the comments are used for multiline comments. Any text in between these two things will be comsidered as comment and is not executed as code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;#Script to show how to use variables    &lt;/span&gt;

&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10 &lt;span class="c"&gt;#do not use space in between&lt;/span&gt;

&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Ryle"&lt;/span&gt;

&lt;span class="nv"&gt;age&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;45

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"My name is &lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="s2"&gt; and age is &lt;/span&gt;&lt;span class="nv"&gt;$age&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;


&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Phoenix"&lt;/span&gt; &lt;span class="c"&gt;#variables are reassignable&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"My name is &lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;##----------------------------------------##&lt;/span&gt;
&lt;span class="c"&gt;#var to store the output of a command&lt;/span&gt;

&lt;span class="nv"&gt;HOSTNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;hostname&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="c"&gt;#`hostname` shows your pc name&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Name of this machine is &lt;/span&gt;&lt;span class="nv"&gt;$HOSTNAME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; 

&lt;span class="nv"&gt;CURR_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="c"&gt;#current directory&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Current directory is &lt;/span&gt;&lt;span class="nv"&gt;$CURR_DIR&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;a=10&lt;/code&gt;: This line assigns the value 10 to the variable a. In Bash, you can create variables without explicitly declaring their types. Variables can store numbers, strings, or other data types.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;name="Ryle"&lt;/code&gt; and &lt;code&gt;age=20&lt;/code&gt;: These lines assign values to the variables name and age. name is assigned the string "Ryle," and age is assigned the number 20.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;echo "My name is $name and age is $age"&lt;/code&gt;: This line uses the echo command to print a message that includes the values of the name and age variables. The $name and $age inside the double-quoted string are used to insert the values of the variables into the string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;use &lt;code&gt;readonly&lt;/code&gt; keyword for constant variable.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Array
&lt;/h2&gt;

&lt;p&gt;This is how arrays are written in shell scripting file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;#Array&lt;/span&gt;

&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;12 21 Hello &lt;span class="s2"&gt;"Ryle Phoenix"&lt;/span&gt; 44 14&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[0]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[2]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[3]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Value at 3rd index: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[3]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"All the values in array: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[*]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="c"&gt;#prints all the values&lt;/span&gt;


&lt;span class="c"&gt;## Array length:&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"length of the array: &lt;/span&gt;&lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[*]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="c"&gt;#prints the length&lt;/span&gt;

&lt;span class="c"&gt;# Getting Certain elements&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Values from index 2 to 4: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[*]&lt;/span&gt;:2:3&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="c"&gt;#how it works: {myArray[*]:start:how_many_elements_you_want}&lt;/span&gt;



&lt;span class="c"&gt;# Update an array with new values: will get added at the end&lt;/span&gt;

myArray+&lt;span class="o"&gt;=(&lt;/span&gt;New 30 40&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Values of new array are: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[*]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Signle words can be stored without semicolons("").
Now, save and run the file using &lt;code&gt;bash fileName.sh&lt;/code&gt; command, you will see the desired output.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Strings
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nv"&gt;myVar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Hey there!!!"&lt;/span&gt;

&lt;span class="nv"&gt;myVarLength&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;myVar&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Length of the myVar is &lt;/span&gt;&lt;span class="nv"&gt;$myVarLength&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;


&lt;span class="c"&gt;#Uppercase&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"In uppercase: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myVar&lt;/span&gt;&lt;span class="p"&gt;^^&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="c"&gt;#lowercase&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"In lowercase: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myVar&lt;/span&gt;&lt;span class="p"&gt;,,&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;


&lt;span class="c"&gt;#replace a word&lt;/span&gt;
&lt;span class="nv"&gt;newVar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myVar&lt;/span&gt;&lt;span class="p"&gt;/there/everyone&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Changed variable is: "&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;newVar&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;


&lt;span class="c"&gt;#slice&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"After slice: "&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myVar&lt;/span&gt;:4:5&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Signle words can be stored without semicolons("").&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  User Input
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;# Taking user input&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Enter your name: "&lt;/span&gt;
&lt;span class="nb"&gt;read &lt;/span&gt;name
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Name is &lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;#ANOTHER WAY&lt;/span&gt;
&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"What is your name bruh? "&lt;/span&gt; name2
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Your name is &lt;/span&gt;&lt;span class="nv"&gt;$name2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now run the file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arithmetic operatings
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10
&lt;span class="nv"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2

&lt;span class="nv"&gt;mul&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="nv"&gt;$y&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$mul&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="c"&gt;#output: 10*2&lt;/span&gt;

&lt;span class="nb"&gt;let &lt;/span&gt;&lt;span class="nv"&gt;mul2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="nv"&gt;$y&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$mul2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="c"&gt;#20&lt;/span&gt;

&lt;span class="c"&gt;# Direct&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Subtraction is: &lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;$y&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To do mathematical calculations: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Either you have to use &lt;code&gt;let&lt;/code&gt; keyword, when you are assigning a variable&lt;/li&gt;
&lt;li&gt;Or when you are directly printing the calculations you have to use '(())' (double parentheses).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conditionals
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fheysourin%2FShell-Scripting%2Fassets%2F98945276%2F798ddba3-1f64-433a-b458-1d4ad73ae030" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fheysourin%2FShell-Scripting%2Fassets%2F98945276%2F798ddba3-1f64-433a-b458-1d4ad73ae030"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  if-else
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"Enter your marks: "&lt;/span&gt; marks

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$marks&lt;/span&gt; &lt;span class="nt"&gt;-ge&lt;/span&gt; 40 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"You are pass"&lt;/span&gt;
&lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Fail!!!"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;if [[ $marks -ge 40 ]]; then&lt;/code&gt;: This line begins an if statement. It checks whether the value of marks is greater than or equal to 40. If this condition is true, the following commands will be executed.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo "You are pass"&lt;/code&gt;: This line is executed if the condition in the if statement is true. It prints "You are pass" to the screen.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;else&lt;/code&gt;: This line is part of the if statement and is executed if the condition in the if statement is false.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo "Fail!!!"&lt;/code&gt;: This line is executed if the condition in the if statement is false. It prints "Fail!!!" to the screen.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fi&lt;/code&gt;: This line marks the end of the if statement, indicating that there are no more commands to be executed conditionally.&lt;/p&gt;

&lt;h3&gt;
  
  
  elif
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;elif [[ $marks -ge 60 ]]; then&lt;/code&gt;: If the first condition is not met, this block is checked. If the user's marks are greater than or equal to 60, it prints "Good job! You scored a B."&lt;/p&gt;

&lt;p&gt;&lt;code&gt;elif [[ $marks -ge 40 ]]; then&lt;/code&gt;: If neither of the previous conditions is met, this block is checked. If the user's marks are greater than or equal to 40, it prints "You passed with a C."&lt;/p&gt;

&lt;h3&gt;
  
  
  choice
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Provide an option: a for date, b list of files, c check for current directory"&lt;/span&gt;

&lt;span class="nb"&gt;read &lt;/span&gt;choice

&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nv"&gt;$choice&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="c"&gt;#how to write multiple lines in one option:&lt;/span&gt;
    a&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Today is: "&lt;/span&gt;
        &lt;span class="nb"&gt;date
        echo&lt;/span&gt; &lt;span class="s2"&gt;"Ending."&lt;/span&gt;
        &lt;span class="p"&gt;;;&lt;/span&gt;
    b&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
    c&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
    &lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Provide a valid value"&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="k"&gt;esac&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;echo "Provide an option: a for date, b for list of files, c for check the current directory"&lt;/code&gt;: This line prints a menu with options for the user to choose from.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;read choice&lt;/code&gt;: This line reads the user's input and stores it in the variable choice.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;case&lt;/code&gt; statement allows you to evaluate the value of &lt;code&gt;choice&lt;/code&gt; against different patterns:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;a)&lt;/code&gt;: If the value of choice is "a," the code within this block is executed. It prints the current date using the date command. In the above code in option a it is also shown that how you can add multi line instructions.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;b)&lt;/code&gt;: If the value of choice is "b," the ls command is executed, listing the files in the current directory.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;c)&lt;/code&gt;: If the value of choice is "c," the pwd command is executed, displaying the current directory path.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;*)&lt;/code&gt;: If none of the above patterns match (i.e., the user enters an invalid option), this block is executed, and it prints "Provide a valid value."&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;;;&lt;/code&gt; statement marks the end of each block within the case statement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Logical Operators
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;#AND&lt;/span&gt;

&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"Enter your age: "&lt;/span&gt; age
&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"Your nationality: "&lt;/span&gt; nat

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$age&lt;/span&gt; &lt;span class="nt"&gt;-ge&lt;/span&gt; 18 &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$nat&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; &lt;span class="s2"&gt;"Indian"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"You can vote!!!"&lt;/span&gt;
&lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"You can not vote"&lt;/span&gt;

&lt;span class="k"&gt;fi&lt;/span&gt;


&lt;span class="c"&gt;# OR&lt;/span&gt;

&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"Enter your age again: "&lt;/span&gt; age
&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"Your nationality again: "&lt;/span&gt; nat

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$age&lt;/span&gt; &lt;span class="nt"&gt;-ge&lt;/span&gt; 18 &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$nat&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; &lt;span class="s2"&gt;"Indian"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"You can vote!!!"&lt;/span&gt;
&lt;span class="k"&gt;else
        &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"You can not vote"&lt;/span&gt;

&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In logical Operators we use &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt; according to our needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ternary Operator
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"Enter your age: "&lt;/span&gt; age
&lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$age&lt;/span&gt; &lt;span class="nt"&gt;-ge&lt;/span&gt; 18 &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Adult"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Minor"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above case if age is greater than or equal to 18 then the program will print "Adult" or it will print "Minor".&lt;/p&gt;

&lt;h2&gt;
  
  
  Loops
&lt;/h2&gt;

&lt;h3&gt;
  
  
  for loop
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;# Loop from 1 to 5&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;1..5&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;let &lt;/span&gt;&lt;span class="nv"&gt;mul&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Iteration &lt;/span&gt;&lt;span class="nv"&gt;$mul&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done


for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;1..10&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Multiplication table: &lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;i&lt;span class="k"&gt;))&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;

&lt;span class="c"&gt;# Iteration over strings&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;name &lt;span class="k"&gt;in &lt;/span&gt;Raju Sham Baburao&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Name is &lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The first loop iterates over numbers from 1 to 5 (inclusive) using the brace expansion &lt;code&gt;{1..5}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The second loop iterates over numbers from 1 to 10 (inclusive) using the brace expansion &lt;code&gt;{1..10}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  for loop iteration on files
&lt;/h2&gt;

&lt;p&gt;Create a file named &lt;code&gt;names.txt:&lt;/code&gt;. Add the following things in the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ryle
Max
Sourin
Oslo
Professor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, create a shell script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;#Getting values from a file names.txt&lt;/span&gt;

&lt;span class="nv"&gt;FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/home/heysourin/Desktop/shell-scripts/names.txt"&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;name &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="nv"&gt;$FILE&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;do
       &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Name is &lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;       
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You have to add proper location of the file and store that inside a variable (FILE in this case).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cat fileName.txt&lt;/code&gt; reads a file and prints the output on the shell itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  for loop on an array
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt; 1 2 3 Hello Hi &lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nv"&gt;length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[*]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;((&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="p"&gt;;&lt;/span&gt;i&amp;lt;&lt;span class="nv"&gt;$length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;i++ &lt;span class="o"&gt;))&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;do
        &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Value of array is &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  while loop
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0
&lt;span class="nv"&gt;num&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$count&lt;/span&gt; &lt;span class="nt"&gt;-le&lt;/span&gt; &lt;span class="nv"&gt;$num&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Value of count var is &lt;/span&gt;&lt;span class="nv"&gt;$count&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;let &lt;/span&gt;count++
&lt;span class="k"&gt;done&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  until loops
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It is a special type of loop seen in shell scripting
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10

&lt;span class="k"&gt;until&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; 1 &lt;span class="o"&gt;]]&lt;/span&gt;
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Value of a is &lt;/span&gt;&lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;let &lt;/span&gt;a--
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The loop will run until &lt;code&gt;a&lt;/code&gt;'s value becomes equal to &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Infinite loop using while loop
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;true
&lt;/span&gt;&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hi"&lt;/span&gt;
    &lt;span class="nb"&gt;sleep &lt;/span&gt;2s &lt;span class="c"&gt;#will run every 2 sec&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This is how we write a infinite loop.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sleep 2s&lt;/code&gt;: It will trigger the loop to run every 2 seconds.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Infinite loop using for loop
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;((&lt;/span&gt; &lt;span class="p"&gt;;;&lt;/span&gt;  &lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hi buddy"&lt;/span&gt;
    &lt;span class="nb"&gt;sleep &lt;/span&gt;2s

&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reading a file using while loop
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;names.txt&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ryle
Max
Sourin
Oslo
Professor

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Shell script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;## Reading a content from a file&lt;/span&gt;
&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;read &lt;/span&gt;myVar
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Value from file is &lt;/span&gt;&lt;span class="nv"&gt;$myVar&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt; &amp;lt; names.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="k"&gt;function &lt;/span&gt;myFunc &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"-------------"&lt;/span&gt;
       &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Welcome"&lt;/span&gt;
       &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"-------------"&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

myFunc
myFunc
myFunc


&lt;span class="c"&gt;## another way&lt;/span&gt;
welcomeNote&lt;span class="o"&gt;(){&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hi there, please come in!!"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
welcomeNote
welcomeNote
welcomeNote

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Function with arguments
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;#ps: space after function-name is mandatory&lt;/span&gt;

&lt;span class="k"&gt;function &lt;/span&gt;welcomeNote &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"--------------------"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Welcome &lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"--------------------"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Age is &lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

welcomeNote Sourin 94 &lt;span class="c"&gt;#calling the function with argument1 and argument2&lt;/span&gt;
welcomeNote Max 32 &lt;span class="c"&gt;#calling the function with argument1 and argument2&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Arguments passing directly on the shell
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;#to access the arguments&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"First argument is &lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Second argument is &lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;


&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"All the arguments are - &lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="c"&gt;#prints all the args&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Number of arguments are - $#"&lt;/span&gt; &lt;span class="c"&gt;#prints total number of args&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You will save the file and run it like this: &lt;code&gt;bash fileName.sh Hello 12&lt;/code&gt;, &lt;code&gt;Hello&lt;/code&gt; and &lt;code&gt;12&lt;/code&gt; is the argument1 and argument2 in this case, which we are passing directly on the shell while we try to run the file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  break &amp;amp; continue statement
&lt;/h2&gt;

&lt;h3&gt;
  
  
  break
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;# example of break in a loop&lt;/span&gt;

&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"Enter the number you want between 1 to 9: "&lt;/span&gt; no

&lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;1..9&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="c"&gt;#Break the loop if number found&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$no&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;
    &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$no&lt;/span&gt;&lt;span class="s2"&gt; is found!!!"&lt;/span&gt;
        &lt;span class="nb"&gt;break
    &lt;/span&gt;&lt;span class="k"&gt;fi
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Number is &lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When if statement will find the desired condition, it will execute brake statement and will stop the program.&lt;/p&gt;

&lt;h3&gt;
  
  
  continue
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;


&lt;span class="c"&gt;#Program to print odd numbers&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;1..10&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;let &lt;/span&gt;&lt;span class="nv"&gt;r&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;%2
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$r&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; 0 &lt;span class="o"&gt;]]&lt;/span&gt;
    &lt;span class="k"&gt;then
        continue
    fi
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Odd no. is &lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above is a shell script to print odd number, when if statement will satisfy its condition the particular condition will be skipped and will print the rest of the things.&lt;/p&gt;

&lt;h2&gt;
  
  
  sleep/ exit/ &lt;code&gt;$?&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sleep&lt;/code&gt; : We have discussed this previously, it creates a delay between two executions.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;exit&lt;/code&gt;: to stop the whole program at some certain point.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$1&lt;/code&gt;: It is used to check if the previous command executed successfully or not. If it returns &lt;code&gt;0&lt;/code&gt;, that means previous command ran successfully and exited with 0. If it returns &lt;code&gt;1&lt;/code&gt;, that means previous command was not executed successfully.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Connectivity Check
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ping -c 1 www.google.com&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If it returns something like this &lt;code&gt;--- www.google.com ping statistics ---&lt;br&gt;
1 packets transmitted, 1 received, 0% packet loss, time 0ms&lt;br&gt;
rtt min/avg/max/mdev = 174.026/174.026/174.026/0.000 ms&lt;/code&gt;. Then the connection is successful.&lt;/p&gt;
&lt;h2&gt;
  
  
  Check if a file and directory exists
&lt;/h2&gt;

&lt;p&gt;Will be using it inside a shell scipt, in a if else statement. I am showing the initial part only.&lt;/p&gt;
&lt;h3&gt;
  
  
  directory
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;if [ -d folederName ]&lt;/code&gt;&lt;br&gt;
&lt;code&gt;if [ ! -d folederName ]&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  file
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;if [ -d fileName ]&lt;/code&gt;&lt;br&gt;
&lt;code&gt;if [ ! -d fileName ]&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Bash Variables
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;RANDOM&lt;/code&gt;: Generates a random integer value from0 to 32767. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;UID&lt;/code&gt;: User Id of the user, that you are currently logged in as. (eg: For root user it will return 0)&lt;/p&gt;
&lt;h2&gt;
  
  
  Login as root user
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;sudo su -&lt;/code&gt;: It will ask for your password, then will open root user mode. You can exit the mode by using &lt;code&gt;exit&lt;/code&gt; command.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is root user?
&lt;/h3&gt;
&lt;h2&gt;
  
  
  Redirection
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

ping &lt;span class="nt"&gt;-c&lt;/span&gt; 1 www.google.com &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; redirect.log

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When you run this script, you will not see any output on the terminal. A file named &lt;code&gt;redirect.log&lt;/code&gt; will be created and the result will be saved in that file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;gt; redirect.log&lt;/code&gt;: A new file is created where all the data will be saved.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you want to add any other data to the same file then you will have to use &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; command, like:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

ping &lt;span class="nt"&gt;-c&lt;/span&gt; 1 www.google.com &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; redirect.log

&lt;span class="nb"&gt;date&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; redirect.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;current date will be saved in the file again, below the previous data.&lt;/p&gt;
&lt;h2&gt;
  
  
  Log messages
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

logger &lt;span class="s2"&gt;"This is a log from &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;0&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The result will not be printed on the shell. It can be seen on the logger messages. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to access log messages?
&lt;code&gt;sudo less var/log/messages&lt;/code&gt; or &lt;code&gt;sudo less var/log/syslog&lt;/code&gt; will show you the log messages.
## Debugging
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt;
&lt;span class="nb"&gt;pwd
date
cd&lt;/span&gt; /root
&lt;span class="nb"&gt;hostname&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Adding &lt;code&gt;set -x&lt;/code&gt; or &lt;code&gt;set -c&lt;/code&gt; after &lt;code&gt;#!/bin/bash&lt;/code&gt; line in any script will help you debugging it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Running a file in the background
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For that first of all you have to approve few permissions of the file:
&lt;code&gt;chmod +x fileName.sh&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;then&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nohup ./fileName.sh&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It will run the script in the background, it will not stop even after terminating the shell.&lt;/li&gt;
&lt;li&gt;It will create a nohup.out file, that you can read later using &lt;code&gt;cat nohup.out&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Automation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You can set any task to run at a particular time by using &lt;code&gt;at&lt;/code&gt; command. On the shell:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Step 1: run this &lt;code&gt;at 21:00 02 September&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Step 2: you'll get some outputs like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;warning: commands will be executed using /bin/sh
at Sat Sep  2 21:00:00 2023
at&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: Then enter your task, eg: &lt;code&gt;bash home/Desktop/folederName/fileName.sh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Step 4: Press &lt;code&gt;Ctrl + D&lt;/code&gt; to save and exit.&lt;/p&gt;

&lt;p&gt;Your script will run at its scheduled time.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;atq&lt;/code&gt;: To see all the scheduled tasks, that has not been executed yet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;atrm&lt;/code&gt;: To delete a scheduled task that has not been executed yet.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>shellscripting</category>
      <category>devops</category>
      <category>cloud</category>
      <category>linux</category>
    </item>
    <item>
      <title>DevOps Learning ~ Day 1</title>
      <dc:creator>Sourin🥑 | Web 3.0 &amp; Blockchain🚀</dc:creator>
      <pubDate>Sun, 20 Aug 2023 13:56:15 +0000</pubDate>
      <link>https://dev.to/heysourin/devops-learning-day-1-6l</link>
      <guid>https://dev.to/heysourin/devops-learning-day-1-6l</guid>
      <description>&lt;p&gt;Starting a new journey is always an exciting endeavour, and today marked the beginning of my exploration into the world of DevOps. Today I have learned the fundamentals, I was introduced to a plethora of concepts that lay the foundation for this intriguing field.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i0LSCqg1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcmqz43236x4fts7osmi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i0LSCqg1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcmqz43236x4fts7osmi.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Need for DevOps
&lt;/h2&gt;

&lt;p&gt;At the core of my day 1 learning, I understood the fact that why DevOps has become an integral part of modern day software development. DevOps isn’t just a buzzword. It’s a method that bridges the gap between development and operations, ensures seamless collaboration and continuous integration. As I pondered the challenges faced during traditional software development, the reasons for adopting DevOps became clear — faster releases, improved collaboration, and enhanced quality assurance.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Dance of Software Development Life Cycle (SDLC)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tf-fLuM3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s020aaxkqht25uhdurxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tf-fLuM3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s020aaxkqht25uhdurxc.png" alt="Image description" width="800" height="671"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the first concepts I encountered was the Software Development Life Cycle (SDLC). It’s the backbone of any software project, comprising phases from idea conception to deployment. DevOps steps onto the stage at crucial points within the SDLC — particularly in building, testing, and deploying software. This real-time collaboration ensures that development and operations teams work in harmony, leading to smoother and more efficient processes.&lt;/p&gt;

&lt;p&gt;If you look at the image carefully; &lt;strong&gt;Building&lt;/strong&gt;, &lt;strong&gt;Testing&lt;/strong&gt; and &lt;strong&gt;Deploying&lt;/strong&gt; is the process that a DevOps engineer mostly works with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Unveiling Virtual Machines and Cloud Computing
&lt;/h2&gt;

&lt;p&gt;As I progressed in my learning, I found myself unveiling the mysteries of virtual machines (VMs) and cloud computing. VMs are like digital versions of physical computers, allowing a user to run multiple operating systems on a single physical machine. The concept of cloud computing, on the other hand, revolutionised the way we deploy and manage a system. It offers scalability, flexibility, and the power to spin up resources as needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basics of Cloud Computing:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Flexibility and Scalability: Cloud computing provides the ability to adjust resources based on demand. Unlike physical servers that require lot of investments and can be challenging to scale and manage. Cloud services allow users to provision additional resources or reduce them as required.&lt;/li&gt;
&lt;li&gt;Cost Efficiency: Cloud services operate on a pay-as-you-go model, meaning you only pay for the resources that you use. This eliminates the need for large capital investments in hardware, reducing financial risks. Additionally, you avoid costs associated with maintaining and upgrading physical servers.&lt;/li&gt;
&lt;li&gt;Resource Management: Cloud providers are the one who manage the underlying infrastructure, including hardware maintenance, updates, and security patches. This allows businesses to focus on their core competencies without dedicating significant resources, time and labour to server management.&lt;/li&gt;
&lt;li&gt;Global Accessibility: Cloud services offer global accessibility. Users can access their applications and data from anywhere in the world with an internet connection. This is a significant advantage over traditional setups that require physical presence in data centers.&lt;/li&gt;
&lt;li&gt;Rapid Deployment: Setting up physical servers can take a lot of time due to procurement, setup, and configuration. Cloud resources can be provisioned in very less time within minutes, enabling rapid deployment of applications and services.&lt;/li&gt;
&lt;li&gt;Global Reach: Cloud providers have data centers located in various locations around the world. This allows businesses to deliver content and services with low latency to users across different geographical locations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Role of a DevOps Engineer
&lt;/h2&gt;

&lt;p&gt;To start with the basics:&lt;/p&gt;

&lt;p&gt;i. Automation&lt;/p&gt;

&lt;p&gt;ii. Monitoring and Alerting&lt;/p&gt;

&lt;p&gt;iii. Security and Compliance&lt;/p&gt;

&lt;p&gt;iv. Version Control&lt;/p&gt;

&lt;p&gt;v. CI/CD&lt;/p&gt;

&lt;p&gt;vi. Documentation&lt;/p&gt;

&lt;p&gt;Understanding the role of a DevOps engineer was a pivotal moment in my day 1 journey. A DevOps engineer isn’t just a coder or an operations guru — they are the bridge between development and operations. They orchestrate processes, automate tasks, and champion a culture of collaboration. Their expertise lies in tools that streamline the entire development lifecycle, from code creation to deployment.&lt;/p&gt;

&lt;p&gt;As I wrap up my reflections on day 1, I’m excited to have embarked on this DevOps journey. From the essentials of why DevOps matters to the foundational understanding of SDLC, virtual machines, cloud computing, and the pivotal role of a DevOps engineer, I can already see the immense potential this field holds.&lt;/p&gt;

&lt;p&gt;Stay tuned as I dive deeper into the DevOps universe, exploring the tools, practices, and technologies that make this methodology a game-changer in modern software development. &lt;/p&gt;




&lt;h2&gt;
  
  
  Basic Commands of Linux
&lt;/h2&gt;

&lt;p&gt;Explore essential Linux commands, file system navigation, permissions of the 1st day.&lt;/p&gt;

&lt;p&gt;**&lt;em&gt;whoami&lt;/em&gt; **Displays the current user’s username.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;pwd&lt;/em&gt;&lt;/strong&gt; Prints the current working directory (i.e., the path to the directory you’re in).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;ls&lt;/em&gt;&lt;/strong&gt; Lists files and directories in the current directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;ls -a&lt;/em&gt;&lt;/strong&gt; Lists all files and directories, including hidden ones (those starting with &lt;code&gt;.&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;ls -la&lt;/em&gt;&lt;/strong&gt; Lists all files and directories in a detailed, long format, including hidden ones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;mkdir folderName&lt;/em&gt;&lt;/strong&gt; Creates a new directory with the specified name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;cd folderName&lt;/em&gt;&lt;/strong&gt; Changes the current directory to the specified folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;cd ..&lt;/em&gt;&lt;/strong&gt; Moves up one directory level.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;cd&lt;/em&gt;&lt;/strong&gt; Changes to the user’s home directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;touch fileName.txt&lt;/em&gt;&lt;/strong&gt; Creates a new empty file with the specified name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;echo “Hello world”&lt;/em&gt;&lt;/strong&gt; Prints the text “Hello world” to the terminal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;mv fileName.txt folderName2&lt;/em&gt;&lt;/strong&gt; Moves the file &lt;code&gt;fileName.txt&lt;/code&gt; to &lt;code&gt;folderName2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;nano&lt;/em&gt;&lt;/strong&gt; Opens the Nano text editor to create or edit files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;cat fileName.txt&lt;/em&gt;&lt;/strong&gt; Displays the content of the file &lt;code&gt;fileName.txt&lt;/code&gt; in the terminal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;history&lt;/em&gt;&lt;/strong&gt; Displays a list of recently executed commands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;rm fileName.txt&lt;/em&gt;&lt;/strong&gt; Deletes the file &lt;code&gt;fileName.txt&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System Management:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;sudo apt install nodejs&lt;/em&gt;&lt;/strong&gt; Installs the Node.js package using the APT package manager with superuser privileges.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;sudo apt update&lt;/em&gt;&lt;/strong&gt; Updates the package list and information for available software packages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; It is recommended to use &lt;code&gt;apt&lt;/code&gt; commands on the terminal and &lt;code&gt;apt-get&lt;/code&gt; in bash scripts. This is because &lt;code&gt;apt&lt;/code&gt; is the newer version and is constantly evolving, which can sometimes break backward compatibility. Using &lt;code&gt;apt-get&lt;/code&gt; commands ensures guaranteed backward compatibility and provides more functionality for script usage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;man &lt;/em&gt;&lt;/strong&gt; Displays the manual page for the specified topic, providing detailed information about commands and concepts.&lt;/p&gt;




&lt;p&gt;Until next time :) Connect me &lt;a href="https://linktr.ee/heysourin"&gt;here&lt;/a&gt; :)&lt;/p&gt;

</description>
      <category>devops</category>
      <category>aws</category>
      <category>linux</category>
    </item>
    <item>
      <title>50+ Web3 and Blockchain Keywords Explained</title>
      <dc:creator>Sourin🥑 | Web 3.0 &amp; Blockchain🚀</dc:creator>
      <pubDate>Mon, 10 Jul 2023 06:40:41 +0000</pubDate>
      <link>https://dev.to/heysourin/50-web3-and-blockchain-keywords-explained-gd3</link>
      <guid>https://dev.to/heysourin/50-web3-and-blockchain-keywords-explained-gd3</guid>
      <description>&lt;p&gt;&lt;strong&gt;Web3.0:&lt;/strong&gt; Web3.0, also known as Web3, refers to the next generation of the internet that incorporates decentralized technologies such as blockchain, cryptocurrencies, and peer-to-peer networks. Web3.0 aims to empower users with more control over their data, privacy, and online interactions. It envisions a more open, transparent, and user-centric internet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decentralization:&lt;/strong&gt; Decentralization refers to the distribution of control and decision-making across a network, rather than being held by a central authority. In the context of Web3 and blockchain, decentralization is a key principle that aims to eliminate the need for intermediaries and allows participants to have more control over their data and transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Smart Contract:&lt;/strong&gt; A smart contract is a self-executing contract with the terms of the agreement directly written into code. Smart contracts are deployed on blockchain platforms and automatically execute predefined actions when certain conditions are met. They enable trustless and transparent interactions between parties.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decentralized Finance (DeFi):&lt;/strong&gt; Decentralized Finance (DeFi) refers to the use of blockchain technology and smart contracts to recreate traditional financial systems in a decentralized manner. DeFi aims to provide financial services such as lending, borrowing, and trading without the need for intermediaries like banks. It enables greater accessibility and transparency in financial transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-Fungible Token (NFT):&lt;/strong&gt; A Non-Fungible Token (NFT) is a unique digital asset that represents ownership or proof of authenticity of a specific item or piece of content. NFTs have gained popularity in the art and collectibles space. Each NFT has a unique identifier and cannot be exchanged on a one-to-one basis like cryptocurrencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interoperability:&lt;/strong&gt; Interoperability refers to the ability of different blockchain networks or systems to communicate and interact with each other seamlessly. It is important for enabling data and asset transfer between different blockchains and ensuring compatibility between various chains.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consensus Mechanism:&lt;/strong&gt; A consensus mechanism is a protocol or algorithm used to achieve agreement among participants in a distributed network. Consensus mechanisms ensure that all nodes in a blockchain network agree on the validity of transactions and the order in which they are added to the blockchain. Examples include Proof of Work (PoW) and Proof of Stake (PoS).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proof of Work (PoW):&lt;/strong&gt; Consensus mechanism where miners solve complex puzzles to validate transactions, ensuring security and immutability by making tampering computationally expensive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proof of Stake (PoS):&lt;/strong&gt; Consensus mechanism where validators create blocks based on staked cryptocurrency, promoting energy efficiency, scalability, and faster block validation without intensive computational puzzles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Distributed Ledger Technology (DLT):&lt;/strong&gt; Distributed Ledger Technology (DLT) is a broader term that encompasses blockchain technology. It refers to a decentralized and distributed database that records and stores transactions across multiple nodes or computers. Blockchain is a specific type of DLT.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cryptocurrency:&lt;/strong&gt; Cryptocurrency is a digital or virtual form of currency that uses cryptography for security. It operates on decentralized networks, typically based on blockchain technology. Examples of cryptocurrencies include Bitcoin (BTC) and Ethereum (ETH).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gas:&lt;/strong&gt; Gas refers to the unit of measurement for the computational effort required to execute transactions or smart contracts on the Ethereum blockchain. Gas is paid in Ether (ETH) and helps prevent spam and abuse by requiring users to pay for the computational resources they consume.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Oracles:&lt;/strong&gt; Oracles are services or mechanisms that provide external data to smart contracts on the blockchain. They act as bridges between the blockchain and the real world, enabling smart contracts to interact with off-chain data sources, such as APIs, to make informed decisions and trigger actions based on real-time information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Chain:&lt;/strong&gt; Cross-chain refers to the ability to transfer assets or data between different blockchain networks. It involves interoperability and allows users to move assets seamlessly across different blockchains, facilitating increased liquidity and expanding the possibilities for decentralized applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decentralized Autonomous Organization (DAO):&lt;/strong&gt; A Decentralized Autonomous Organization (DAO) is an organization that operates through smart contracts on a blockchain. It is governed by a set of predefined rules and decisions are made through voting by token holders. DAOs aim to eliminate the need for traditional hierarchical structures and allow for decentralized decision-making.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer 2 Scaling:&lt;/strong&gt; Layer 2 scaling solutions are techniques or protocols built on top of existing blockchains to improve scalability and increase transaction throughput. They aim to handle a larger number of transactions off-chain or in a more efficient manner, reducing congestion and lowering transaction costs. Examples of layer 2 scaling solutions include state channels and sidechains.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Permissionless:&lt;/strong&gt; Permissionless refers to the openness and accessibility of a blockchain network or protocol. In a permissionless network, anyone can participate, validate transactions, and contribute to the network without requiring explicit permission. This characteristic is a fundamental aspect of many blockchain networks, enabling anyone to join and interact with the network without needing approval from a central authority.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hard Fork:&lt;/strong&gt; A hard fork is a type of upgrade or change to a blockchain protocol that is not backward compatible with older versions. It requires all participants in the network to upgrade to the new version in order to continue participating. Hard forks can result in a split in the blockchain, creating two separate chains with different rules and potentially leading to the creation of a new cryptocurrency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Halving:&lt;/strong&gt; Halving is an event that occurs in some cryptocurrencies, such as Bitcoin, where the block reward for miners is reduced by half after a certain number of blocks are mined. This event is programmed into the cryptocurrency's protocol and is designed to control the issuance of new coins and create scarcity over time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hashing Algorithm:&lt;/strong&gt; Hashing is a process used in computing to generate a unique and fixed-size string of characters (hash) from input data of any size. In the context of blockchain, hashing is used to create a digital fingerprint of data, such as transactions or blocks, ensuring their integrity and allowing for easy verification. Hashes are used to confirm the completeness and validity of blockchain transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Censorship Resistance:&lt;/strong&gt; Censorship resistance refers to the ability of a system or platform to resist censorship or control by centralized authorities. In Web3, blockchain-based platforms provide censorship resistance by decentralizing control and allowing users to have ownership and control over their data and transactions. This enables freedom of expression and protects against arbitrary censorship or manipulation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decentralized Exchange (DEX):&lt;/strong&gt; A decentralized exchange is a type of cryptocurrency exchange that operates on a blockchain network without the need for intermediaries or a central authority. DEXs allow users to trade cryptocurrencies directly with each other, using smart contracts for order matching and execution. They provide increased privacy, security, and control over assets compared to centralized exchanges.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Immutable Ledger:&lt;/strong&gt; An immutable ledger refers to a blockchain's characteristic of being tamper-resistant and unchangeable once data is added to it. Once a transaction or data is recorded on the blockchain, it becomes part of a permanent and transparent history that cannot be altered or deleted. This property ensures the integrity and trustworthiness of the data stored on the blockchain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decentralized Exchange (DEX):&lt;/strong&gt; A decentralized exchange is a type of cryptocurrency exchange that operates on a blockchain network without the need for intermediaries or a central authority. DEXs allow users to trade cryptocurrencies directly with each other, using smart contracts for order matching and execution. They provide increased privacy, security, and control over assets compared to centralized exchanges.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Token Standards:&lt;/strong&gt; Token standards are specific protocols or sets of rules that define the functionality and behavior of tokens on a blockchain. Examples of token standards include ERC-20 for fungible tokens, ERC-721 for non-fungible tokens (NFTs), and ERC-1155 for multi-token standards. Token standards ensure interoperability and compatibility between different tokens and enable developers to build applications that interact with tokens in a standardized way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decentralized File Storage:&lt;/strong&gt; Decentralized file storage refers to the storage of data on a distributed network of nodes, rather than relying on a centralized server or provider. Blockchain-based decentralized file storage systems, such as IPFS (InterPlanetary File System) or Filecoin, allow users to store and retrieve data in a secure, distributed, and censorship-resistant manner.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tokenomics:&lt;/strong&gt; Tokenomics refers to the economic design and structure of a cryptocurrency or token ecosystem. It encompasses factors such as token supply, distribution, utility, governance mechanisms, and incentives. Tokenomics aims to create a sustainable and balanced ecosystem that aligns the interests of token holders, users, and other stakeholders in the network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Zero-knowledge proofs (ZKPs):&lt;/strong&gt; ZKPs are cryptographic protocols that allow one party (the prover) to prove the knowledge of a certain piece of information to another party (the verifier) without revealing the actual information itself. The goal of zero-knowledge proofs is to convince the verifier of the truthfulness of a statement without disclosing any additional information beyond the validity of the statement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ethereum:&lt;/strong&gt; Ethereum is an open-source, blockchain-based platform that enables developers to build and deploy decentralized applications (dApps). It was proposed by Vitalik Buterin in late 2013 and development was crowdfunded in 2014. Ethereum's blockchain is fundamentally different from Bitcoin's blockchain. While Bitcoin's blockchain is used to track ownership of digital currency (bitcoins), the Ethereum blockchain focuses on running programming code of any decentralized application&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bitcoin:&lt;/strong&gt; Bitcoin, often described as a cryptocurrency, a virtual currency or a digital currency, is a type of money that is completely virtual. It's like an online version of cash. You can use it to buy products and services, but not many shops accept Bitcoin yet and some countries have banned it altogether. Bitcoin was the first cryptocurrency and remains the most important in the market. It was invented in 2008 by an unknown person or group of people using the name Satoshi Nakamoto.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ICO:&lt;/strong&gt; ICO stands for Initial Coin Offering and it's often used as a fundraiser for new projects. This is where a company looking to raise money to create a new coin, app, or service launches an ICO as a way to raise funds. People who buy into the ICO receive a certain number of tokens in return. ICOs are often compared to IPOs (Initial Public Offerings), but there are some significant differences&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Public Key:&lt;/strong&gt; In the world of cryptocurrencies, a public key represents a point on a particular Elliptic Curve (EC) defined in secp256k1. Public keys contain an identification byte, a 32-byte X coordinate, and a 32-byte Y coordinate. They are used in Bitcoin and other cryptocurrencies for generating addresses where funds can be seen&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Private Key:&lt;/strong&gt; In cryptocurrencies, a private key allows a user to gain full access to their wallet. The person who holds the private key fully controls the coins in that wallet. For this reason, it should be kept secret. Formally, a private key for Bitcoin (and many other cryptocurrencies) is a series of 32 bytes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stablecoin:&lt;/strong&gt; Stablecoins are a type of cryptocurrency designed to minimize volatility, a common issue with cryptocurrencies like Bitcoin. They achieve this stability by pegging their market value to an external reference, usually a fiat currency like the US dollar, or a commodity like gold. Some stablecoins maintain reserve assets as collateral, while others use algorithmic formulas to control supply. The primary purpose of stablecoins is to provide a more suitable option for common transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Altcoin:&lt;/strong&gt; The term altcoin refers to all cryptocurrencies other than Bitcoin and, for some, Ethereum. These alternative cryptocurrencies come in various types, each designed for different purposes. While the future value of altcoins is unpredictable, as long as the blockchain they were designed for continues to be used and developed, the altcoins will continue to exist. It's important to note that while many altcoins offer potential investment opportunities, some are scams or have lost developer and community interest&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mainnet:&lt;/strong&gt; It refers to the main blockchain network of a cryptocurrency, where real transactions and operations take place. It is the live and production-ready network where actual value is exchanged. Mainnet is typically used for real-world applications, and transactions on the mainnet involve real cryptocurrencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testnet:&lt;/strong&gt; on the other hand, is a separate network specifically designed for testing and development purposes. It mimics the functionalities of the mainnet but uses test tokens or simulated cryptocurrencies that have no real-world value. Testnets allow developers and users to experiment, validate, and debug their applications without risking real funds. It provides a safe environment for testing new features, smart contracts, and conducting simulations before deploying on the mainnet. Testnets are crucial for ensuring the reliability and security of applications before they are deployed to the production-ready mainnet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remix IDE:&lt;/strong&gt; is an online development environment for writing, testing, and deploying smart contracts on the Ethereum blockchain. It provides a user-friendly interface with a built-in code editor, compiler, debugger, and deployment tools. Remix IDE allows developers to write Solidity smart contracts, interact with contracts using a web3 provider, and test their code using various tools and plugins. It is a popular choice for Ethereum developers due to its simplicity and comprehensive features.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Infura/Alchemy:&lt;/strong&gt; It is a popular service that provides infrastructure and API endpoints for connecting to the Ethereum blockchain. It acts as a web3 provider, allowing developers to interact with the Ethereum network without running a full Ethereum node. Infura simplifies the development process by providing reliable and scalable access to the Ethereum blockchain, eliminating the need for developers to set up and maintain their own infrastructure. It offers various API endpoints, including JSON-RPC and WebSocket, which developers can use to send transactions, retrieve data, and interact with smart contracts. Infura is widely used by developers to integrate Ethereum functionality into their applications and services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mining:&lt;/strong&gt; Mining is the process of validating and adding new transactions to a blockchain. It involves solving complex mathematical puzzles to find a new block, which contains a set of transactions. Miners compete with each other to solve these puzzles by using computational power, and the first miner to find the solution gets rewarded with newly minted cryptocurrency tokens. Mining ensures the security, integrity, and decentralization of a blockchain network by preventing double-spending and maintaining consensus among participants.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tokenization:&lt;/strong&gt; Tokenization is the process of representing real-world assets or rights as digital tokens on a blockchain. It allows for fractional ownership, increased liquidity, and easier transfer of assets. Tokenization has applications in areas such as real estate, art, and finance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Immutable:&lt;/strong&gt; Immutable means that something is unchangeable or cannot be altered or tampered with. In the context of blockchain, immutability refers to the property of data stored on the blockchain that cannot be modified once it is added to the chain. This ensures the integrity and trustworthiness of the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Merkle Tree:&lt;/strong&gt; A hierarchical data structure that enables efficient verification and integrity checks of large datasets. It uses cryptographic hashing to create a tree structure where each node represents the hash of its child nodes, providing an efficient way to verify the integrity of specific data without needing to examine the entire dataset.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Byzantine Fault Tolerance:&lt;/strong&gt; The ability of a distributed system to reach a consensus even in the presence of malicious or faulty nodes. It ensures system resilience by employing redundancy, replication, and consensus algorithms to tolerate failures and prevent malicious actors from compromising the integrity and reliability of the system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ICO (Initial Coin Offering):&lt;/strong&gt; A fundraising method used by cryptocurrency projects to raise capital. It involves issuing and selling tokens to investors in exchange for cryptocurrencies or fiat currencies, providing early access to the project's tokens and potential returns on investment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Whitepaper:&lt;/strong&gt; A detailed document that outlines the concept, technology, goals, and implementation plan of a cryptocurrency project. It provides an in-depth analysis of the project's vision, technical specifications, tokenomics, and potential impact, serving as a comprehensive guide for investors and stakeholders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yellowpaper:&lt;/strong&gt; Similar to a whitepaper, a yellowpaper is a technical document that provides a deeper technical understanding of a cryptocurrency project. It typically delves into the underlying protocols, algorithms, and technical intricacies of the project, providing detailed explanations and specifications for developers and researchers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fork:&lt;/strong&gt; A divergence in the blockchain where a single chain splits into two separate chains, resulting in two different versions of the blockchain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Soft Fork:&lt;/strong&gt; A backward-compatible upgrade to the blockchain protocol where the new rules are more restrictive than the old rules, allowing the new blocks to be accepted by both old and new nodes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hard Fork:&lt;/strong&gt; A non-backward-compatible upgrade to the blockchain protocol where the new rules are more permissive than the old rules, resulting in a permanent divergence in the blockchain and two separate chains that are incompatible with each other.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>ethereum</category>
    </item>
    <item>
      <title>How to create a Web3 Wallet Like MetaMask? Web3 and Blockchain Project.</title>
      <dc:creator>Sourin🥑 | Web 3.0 &amp; Blockchain🚀</dc:creator>
      <pubDate>Tue, 20 Jun 2023 17:28:33 +0000</pubDate>
      <link>https://dev.to/heysourin/how-to-create-a-web3-wallet-like-metamask-web3-and-blockchain-project-440c</link>
      <guid>https://dev.to/heysourin/how-to-create-a-web3-wallet-like-metamask-web3-and-blockchain-project-440c</guid>
      <description>&lt;p&gt;Here we will create a web3 wallet like MetaMask using tech stacks like Ethers.js(v5), React, TypeScript and Tailwind CSS.&lt;/p&gt;

&lt;p&gt;For reference I recommend you to watch this &lt;a href="https://youtu.be/hztdWaXHlMQ"&gt;YouTube video&lt;/a&gt; and this &lt;a href="https://github.com/heysourin/Web3-Wallet-Complete"&gt;GitHub Repo&lt;/a&gt;(Source Code). In the video I have also explained how you can create a Browser extension.&lt;/p&gt;

&lt;p&gt;Our Wallet has 3 parts:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BMn6yxx6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5566dlkxtyl8fo9yaosp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BMn6yxx6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5566dlkxtyl8fo9yaosp.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create New account &amp;amp; Recover existing account&lt;/li&gt;
&lt;li&gt;Fetching balance and sending ETH&lt;/li&gt;
&lt;li&gt;Fetching transaction data from block explorer&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Prerequisite&lt;/strong&gt;: Knowledge of Web3, React.js and Backend Dev&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create New account &amp;amp; Recover existing account:
&lt;/h2&gt;

&lt;p&gt;For account creation and recover we will create React component &lt;code&gt;AccountCreate.tsx&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from "react";
import { generateAccount } from "../wallet-utils/AccountUtils";

import AccountDetails from "./AccountDetails";
import TransactionDetails from "./TransactionDetails";

interface Account {
  privateKey: string;
  address: string;
  balance: string;
}

const AccountCreate: React.FC = () =&amp;gt; {
  const [showInput, setShowInput] = useState(false);
  const [seedPhrase, setSeedPhrase] = useState("");
  const [account, setAccount] = useState&amp;lt;Account | null&amp;gt;(null);

  const createAccount = () =&amp;gt; {
    const account = generateAccount();// account object contains--&amp;gt; address, privateKey, seedPhrase, balance
    console.log("Account created!", account);
    setSeedPhrase(account.seedPhrase);
    setAccount(account.account);
  };

  const showInputFunction = () =&amp;gt; {
    setShowInput(true);
  };

  const handleSeedPhraseChange = (e: React.ChangeEvent&amp;lt;HTMLInputElement&amp;gt;) =&amp;gt; {
    setSeedPhrase(e.target.value);
  };

  const handleSeedPhraseSubmit = (e: React.FormEvent) =&amp;gt; {
    e.preventDefault();
    const account = generateAccount(seedPhrase);
    console.log("Recovery", account);
    setSeedPhrase(account.seedPhrase);
    setAccount(account.account);
  };

  return (
    &amp;lt;div className="max-w-md mx-auto bg-white rounded-md shadow-md p-6"&amp;gt;
      &amp;lt;h2 className="text-2xl font-bold mb-4"&amp;gt;Pixel Web3 Wallet on Polygon Mumbai&amp;lt;/h2&amp;gt;
      &amp;lt;button
        onClick={createAccount}
        className="text-white bg-gradient-to-r from-purple-500 via-purple-600 to-purple-700 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-purple-300 dark:focus:ring-purple-800 shadow-lg shadow-purple-500/50 dark:shadow-lg dark:shadow-purple-800/80 font-medium rounded-lg text-sm px-5 py-2.5 text-center mr-2 mb-2"
      &amp;gt;
        Create Account
      &amp;lt;/button&amp;gt;
      &amp;lt;button
        onClick={showInputFunction}
        className="text-gray-900 bg-gradient-to-r from-lime-200 via-lime-400 to-lime-500 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-lime-300 dark:focus:ring-lime-800 shadow-lg shadow-lime-500/50 dark:shadow-lg dark:shadow-lime-800/80 font-medium rounded-lg text-sm px-5 py-2.5 text-center mr-2 mb-2"
      &amp;gt;
        Recover Account
      &amp;lt;/button&amp;gt;
      {showInput &amp;amp;&amp;amp; (
        &amp;lt;form onSubmit={handleSeedPhraseSubmit} className="flex m-2"&amp;gt;
          &amp;lt;input
            type="text"
            value={seedPhrase}
            onChange={handleSeedPhraseChange}
            className="bg-transparent border border-gray-300 rounded-md w-full py-2 px-4 placeholder-gray-400 text-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 mr-2"
            placeholder="Enter your text"
          /&amp;gt;
          &amp;lt;button
            type="submit"
            className="text-white bg-gradient-to-r from-cyan-400 via-cyan-500 to-cyan-600 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-cyan-300 dark:focus:ring-cyan-800 shadow-lg shadow-cyan-500/50 dark:shadow-lg dark:shadow-cyan-800/80 font-medium rounded-lg text-sm px-5 py-2.5 text-center mr-2 m-2"
          &amp;gt;
            Submit
          &amp;lt;/button&amp;gt;
        &amp;lt;/form&amp;gt;
      )}

      &amp;lt;div&amp;gt;
        &amp;lt;p className=" text-gray-900 font-medium"&amp;gt;A/C Address: &amp;lt;/p&amp;gt;
        &amp;lt;span className="text-gray-600 mt-2"&amp;gt;{account?.address}&amp;lt;/span&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div&amp;gt;
        &amp;lt;p className="text-gray-900  font-medium"&amp;gt;Your 12 Phrase Mnemonic: &amp;lt;/p&amp;gt;
        &amp;lt;span className="text-gray-600 text-normal"&amp;gt;{seedPhrase}&amp;lt;/span&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;hr /&amp;gt;
      {account &amp;amp;&amp;amp; &amp;lt;AccountDetails account={account} /&amp;gt;}
      {account &amp;amp;&amp;amp; &amp;lt;TransactionDetails address={account.address} /&amp;gt;}
    &amp;lt;/div&amp;gt;
  );
};

export default AccountCreate;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above component has an import named generateAccount, which is also the most important function. For that we will refer ‘AccountUtils.ts’ file. We will install &lt;code&gt;npm install ethers@5&lt;/code&gt; . The code is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Wallet } from "ethers";

interface Account {
  privateKey: string;
  address: string;
  balance: string;
}

export function generateAccount(
  seedPhrase: string = "",
  index: number = 0
): { account: Account; seedPhrase: string } {
  let wallet: Wallet;

  if (seedPhrase === "") {
    seedPhrase = Wallet.createRandom().mnemonic.phrase;
  }

  // If the seed phrase does not contain spaces, it is likely a mnemonic
  wallet = seedPhrase.includes(" ")
    ? Wallet.fromMnemonic(seedPhrase, `m/44'/60'/0'/0/${index}`)
    : new Wallet(seedPhrase);

  // console.log("hehe",wallet);

  const { address } = wallet; // we are capturing address variable from 'wallet' object

  const account = { address, privateKey: wallet.privateKey, balance: "0" };

  // If the seedphrase does not include spaces then it's actually a private key, so return a blank string.
  return { account, seedPhrase: seedPhrase.includes(" ") ? seedPhrase : "" };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sums up our first feature that is create and recover accounts!! Let’s move to second one.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Fetching balance and sending ETH
&lt;/h2&gt;

&lt;p&gt;For fetching balance and sending ETH we will create a React component and also create an interface of chains on Ethereum network.&lt;/p&gt;

&lt;p&gt;At the beginning we will create &lt;code&gt;AccountDetails.tsx&lt;/code&gt; component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from "react";
import { Account } from "../interfaces/Account";
import { ethers } from "ethers";
import { mumbai } from "../interfaces/Chain";
import { sendToken } from "../wallet-utils/TransactionUtils";

interface AccountDetailProps {
  account: Account;
}

const AccountDetails: React.FC&amp;lt;AccountDetailProps&amp;gt; = ({ account }) =&amp;gt; {
  const [destinationAddress, setDestinationAddress] = useState("");
  const [amount, setAmount] = useState(0);
  const [balance, setBalance] = useState(account.balance);
  const [networkResponse, setNetworkResponse] = useState&amp;lt;{
    status: null | "pending" | "complete" | "error";
    message: string | React.ReactElement;
  }&amp;gt;({
    status: null,
    message: "",
  });

  const fetchData = async () =&amp;gt; {
    const provider = new ethers.providers.JsonRpcProvider(mumbai.rpcUrl);
    let accountBalance = await provider.getBalance(account.address);
    setBalance(
      String(formatEthFunc(ethers.utils.formatEther(accountBalance)))
    );
  };

  //Required to Format decimals of ETH balance
  function formatEthFunc(value: string, decimalPlaces: number = 2) {
    return +parseFloat(value).toFixed(decimalPlaces);
  }

  useEffect(() =&amp;gt; {
    fetchData();
  }, [account.address]);

  const handleDestinationAddressChange = (
    e: React.ChangeEvent&amp;lt;HTMLInputElement&amp;gt;
  ) =&amp;gt; {
    setDestinationAddress(e.target.value);
  };

  const handleAmountChange = (e: React.ChangeEvent&amp;lt;HTMLInputElement&amp;gt;) =&amp;gt; {
    setAmount(Number.parseFloat(e.target.value));
  };

  const transfer = async () =&amp;gt; {
    setNetworkResponse({
      status: "pending",
      message: "",
    });

    try {
      const { receipt } = await sendToken(
        amount,
        account.address,
        destinationAddress,
        account.privateKey
      );

      if (receipt.status === 1) {
        setNetworkResponse({
          status: "complete",
          message: (
            &amp;lt;p&amp;gt;
              Transfer complete!{" "}
              &amp;lt;a
                href={`${mumbai.blockExplorerUrl}/tx/${receipt.transactionHash}`}
                target="_blank"
                rel="noreferrer"
              &amp;gt;
                View transaction
              &amp;lt;/a&amp;gt;
            &amp;lt;/p&amp;gt;
          ),
        });
        return receipt;
      } else {
        console.log(`Failed to send ${receipt}`);
        // Set the network response status to "error" and the message to the receipt
        setNetworkResponse({
          status: "error",
          message: JSON.stringify(receipt),
        });
        return { receipt };
      }
    } catch (error: any) {
      console.error(error);
      setNetworkResponse({
        status: "error",
        message: error.reason || JSON.stringify(error),
      });
    }
  };

  return (
    &amp;lt;div className=""&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;h4 className="text-gray-900 font-medium"&amp;gt;Address: &amp;lt;/h4&amp;gt;
        &amp;lt;a
          target="blank"
          href={`https://mumbai.polygonscan.com/address/${account.address}`}
          className="text-blue-500 hover:text-blue-600  cursor-pointer"
        &amp;gt;
          {account.address}
        &amp;lt;/a&amp;gt;
        &amp;lt;br /&amp;gt;
        &amp;lt;span className="text-gray-900 font-medium"&amp;gt;Balance: &amp;lt;/span&amp;gt;
        {balance} ETH
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="my-2"&amp;gt;
        &amp;lt;label htmlFor="" className="text-gray-900 font-medium"&amp;gt;
          Destination Address:
        &amp;lt;/label&amp;gt;
        &amp;lt;input
          type="text"
          value={destinationAddress}
          onChange={handleDestinationAddressChange}
          className="border"
        /&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div&amp;gt;
        &amp;lt;label htmlFor="" className="text-gray-900 font-medium"&amp;gt;
          Amount:
        &amp;lt;/label&amp;gt;
        &amp;lt;input
          type="number"
          value={amount}
          onChange={handleAmountChange}
          className="border"
        /&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;button
        className="text-white bg-gradient-to-r from-yellow-400 via-yellow-500 to-yellow-600 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-yellow-300 dark:focus:ring-yellow-800 shadow-lg shadow-yellow-500/50 dark:shadow-lg dark:shadow-yellow-800/80 font-medium rounded-lg text-sm px-5 py-2.5 text-center mr-2 m-2"
        type="button"
        onClick={transfer}
        disabled={!amount || networkResponse.status === "pending"}
      &amp;gt;
        Send {amount} ETH
      &amp;lt;/button&amp;gt;

      {networkResponse.status &amp;amp;&amp;amp; (
        &amp;lt;&amp;gt;
          {networkResponse.status === "pending" &amp;amp;&amp;amp; (
            &amp;lt;p&amp;gt;Transfer is pending...&amp;lt;/p&amp;gt;
          )}
          {networkResponse.status === "complete" &amp;amp;&amp;amp; (
            &amp;lt;p&amp;gt;{networkResponse.message}&amp;lt;/p&amp;gt;
          )}
          {networkResponse.status === "error" &amp;amp;&amp;amp; (
            &amp;lt;p&amp;gt;
              Error occurred while transferring tokens:{" "}
              {networkResponse.message}
            &amp;lt;/p&amp;gt;
          )}
        &amp;lt;/&amp;gt;
      )}
    &amp;lt;/div&amp;gt;
  );
};

export default AccountDetails;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you notice, in the above file we have few interface imports.&lt;/p&gt;

&lt;p&gt;a. Import of account data types, create a file &lt;code&gt;Account.ts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export interface Account {
    privateKey: string,
    address: string,
    balance: string,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b. Import of different networks on Ethereum, create a file &lt;code&gt;Chain.ts&lt;/code&gt;:&lt;br&gt;
Remember in this file you’ll need RPC-URL of the networks, you can get them from Alchemy or Infura or from somewhere else.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export type Chain = {
    chainId: string;
    name: string;
    blockExplorerUrl: string;
    rpcUrl: string;
  };

export const mumbai: Chain = {
    chainId: '80001',
    name: 'Polygon Testnet Mumbai',
    blockExplorerUrl: 'https://mumbai.polygonscan.com ',
    rpcUrl: '&amp;lt;YOUR-RPC-URL&amp;gt;',
};

export const mainnet: Chain = {
    chainId: '1',
    name: 'Ethereum',
    blockExplorerUrl: 'https://etherscan.io',
    rpcUrl: '&amp;lt;YOUR-RPC-URL&amp;gt;',
};

export const CHAINS_CONFIG = {
    [mumbai.chainId]: mumbai,
    [mainnet.chainId]: mainnet,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c. Third imort on AccountDetails.tsx file is &lt;code&gt;TransactionUtils.ts&lt;/code&gt;, which contains the most import function that will be used to transfer ETH.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ethers, Wallet } from "ethers";
import { CHAINS_CONFIG, mumbai } from "../interfaces/Chain";

export async function sendToken(
  amount: number,
  from: string,
  to: string,
  privateKey: string
) {
  const chain = CHAINS_CONFIG[mumbai.chainId];
  const provider = new ethers.providers.JsonRpcProvider(chain.rpcUrl);//creating a
  const wallet: Wallet = new ethers.Wallet(privateKey, provider);

  const tx = { to, value: ethers.utils.parseEther(amount.toString()) };

  const transaction = await wallet.sendTransaction(tx);

  const receipt = await transaction.wait();

  return { transaction, receipt };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;End of the second, now comes the Third part.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Fetching transaction data from block explorer
&lt;/h2&gt;

&lt;p&gt;For this we’ll need API-Key-Token from the block explorer. You can refer the video mentioned in the beginning.&lt;/p&gt;

&lt;p&gt;Create a file &lt;code&gt;TransactionDetails.tsx&lt;/code&gt;. Here you’ll need to have basic understandings of backend development, as we are fetching data using axios.&lt;/p&gt;

&lt;p&gt;We are using base uri and endpoints of Polygonscan as we are fetching data from mumbai test net of polygon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useEffect, useState } from "react";
import axios from "axios";

interface Transaction {
  hash: string;
  from: string;
  to: string;
  isError: string;
  timeStamp: string;
}

interface TransactionTableProps {
  address: string;
}

const MUMBAI_API_KEY = "&amp;lt;YOUR-API-KEY&amp;gt;";
const MUMBAI_API_BASE_URL = "https://api-testnet.polygonscan.com/api";

const TransactionDetails: React.FC&amp;lt;TransactionTableProps&amp;gt; = ({ address }) =&amp;gt; {
  const [transactions, setTransactions] = useState&amp;lt;Transaction[]&amp;gt;([]);

  useEffect(() =&amp;gt; {
    const fetchTransactions = async () =&amp;gt; {
      const endpoint = `?module=account&amp;amp;action=txlist&amp;amp;address=${address}&amp;amp;page=1&amp;amp;offset=10&amp;amp;sort=desc&amp;amp;apikey=${MUMBAI_API_KEY}`;
      const url = `${MUMBAI_API_BASE_URL}${endpoint}`;

      try {
        const response = await axios.get(url);
        const transactionData: Transaction[] = response.data.result;
        setTransactions(transactionData);
      } catch (error) {
        console.error("Error fetching transactions:", error);
      }
    };

    fetchTransactions();
  }, [address]);

  return (
    &amp;lt;table className="min-w-full divide-y divide-gray-200"&amp;gt;
    &amp;lt;thead className="bg-gray-100"&amp;gt;
      &amp;lt;tr&amp;gt;
        &amp;lt;th className="py-2 px-4"&amp;gt;No.&amp;lt;/th&amp;gt;
        &amp;lt;th className="py-2 px-4"&amp;gt;Hash&amp;lt;/th&amp;gt;
        &amp;lt;th className="py-2 px-4"&amp;gt;From&amp;lt;/th&amp;gt;
        &amp;lt;th className="py-2 px-4"&amp;gt;To&amp;lt;/th&amp;gt;
        &amp;lt;th className="py-2 px-4"&amp;gt;Status&amp;lt;/th&amp;gt;
        &amp;lt;th className="py-2 px-4"&amp;gt;Timestamp&amp;lt;/th&amp;gt;
      &amp;lt;/tr&amp;gt;
    &amp;lt;/thead&amp;gt;
    &amp;lt;tbody&amp;gt;
      {transactions.map((transaction, index) =&amp;gt; (
        &amp;lt;tr key={index} className={index % 2 === 0 ? 'bg-gray-50' : ''}&amp;gt;
          &amp;lt;td className="py-2 px-4"&amp;gt;{index + 1}&amp;lt;/td&amp;gt;
          &amp;lt;td className="py-2 px-4"&amp;gt;
            {`${transaction.hash.slice(0, 5)}...${transaction.hash.slice(-3)}`}
          &amp;lt;/td&amp;gt;
          &amp;lt;td className="py-2 px-4"&amp;gt;
            {`${transaction.from.slice(0, 5)}...${transaction.from.slice(-3)}`}
          &amp;lt;/td&amp;gt;
          &amp;lt;td className="py-2 px-4"&amp;gt;
            {`${transaction.to.slice(0, 5)}...${transaction.to.slice(-3)}`}
          &amp;lt;/td&amp;gt;
          &amp;lt;td className="py-2 px-4"&amp;gt;
            {transaction.isError === '0' ? '✅' : '❌'}
          &amp;lt;/td&amp;gt;
          &amp;lt;td className="py-2 px-4"&amp;gt;{transaction.timeStamp}&amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
      ))}
    &amp;lt;/tbody&amp;gt;
  &amp;lt;/table&amp;gt;
  );
};

export default TransactionDetails;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sums up the coding part.&lt;/p&gt;




&lt;p&gt;This is how wallet browser extension looks like, steps are explained in the &lt;a href="https://youtu.be/hztdWaXHlMQ"&gt;YT video&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TguPp6ma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/48ldz8h069ashva0ymkt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TguPp6ma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/48ldz8h069ashva0ymkt.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you stuck anywhere, hit me up&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Generate better response from AI Language Models (ChatGPT, Google BARD) as a Web3 or Blockchain Developer. Step by step guide.</title>
      <dc:creator>Sourin🥑 | Web 3.0 &amp; Blockchain🚀</dc:creator>
      <pubDate>Sat, 17 Jun 2023 16:31:11 +0000</pubDate>
      <link>https://dev.to/heysourin/generate-better-response-from-ai-language-models-chatgpt-google-bard-as-a-web3-or-blockchain-developer-step-by-step-guide-44aj</link>
      <guid>https://dev.to/heysourin/generate-better-response-from-ai-language-models-chatgpt-google-bard-as-a-web3-or-blockchain-developer-step-by-step-guide-44aj</guid>
      <description>&lt;p&gt;The 6 Steps we have to keep in mind.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Context
2. A Specific goal 
3. A specific format 
4. Breaking down into smaller parts 
5. Assign smaller tasks 
6. Providing 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explaining them in a step-by-step way:&lt;br&gt;
&lt;code&gt;Context:&lt;/code&gt; Giving the AI model clear and pertinent context aids in its understanding of the particular issue or subject you want assistance with. The model can better personalise its answer to your needs the more background information you offer.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;A Specific Goal:&lt;/code&gt; Clearly state your goal for the talk or what you hope to accomplish. Having a clear objective aids the AI model in producing solutions that are pertinent and laser-focused.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;A Specific Format:&lt;/code&gt; Indicate the structure or format you like for the response. Mentioning the preferred style, for instance, if you want a step-by-step tutorial, a concise summary, or a comparison of several possibilities, aids the model in producing a more appropriate response.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Breaking Down into Smaller Parts:&lt;/code&gt; Consider dividing a big activity or topic into smaller, more manageable components. This enables the model to address each component independently and offer more thorough and precise replies.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Assigning Smaller Tasks:&lt;/code&gt; Divide the task into tiny sub-tasks rather than giving the model a massive request. The model can handle each sub-task well and deliver more precise and focused replies with the aid of this strategy.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Providing Examples:&lt;/code&gt; Giving particular examples that are connected to your question might help the model grasp it better. The model may provide replies that match the patterns and features given by using examples as reference points.&lt;/p&gt;

&lt;p&gt;Follow for more. Feel free to &lt;a href="https://linktr.ee/heysourin"&gt;connect&lt;/a&gt; :)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Connect Web3 Wallet into your Website? (Web3 and Blockchain project).</title>
      <dc:creator>Sourin🥑 | Web 3.0 &amp; Blockchain🚀</dc:creator>
      <pubDate>Fri, 02 Jun 2023 19:42:39 +0000</pubDate>
      <link>https://dev.to/heysourin/how-to-connect-web3-wallet-into-your-website-web3-and-blockchain-project-7mj</link>
      <guid>https://dev.to/heysourin/how-to-connect-web3-wallet-into-your-website-web3-and-blockchain-project-7mj</guid>
      <description>&lt;p&gt;Connecting a &lt;strong&gt;MetaMask&lt;/strong&gt; wallet to your Web3 website is important for various reasons. It allows you to connect you to your DApps, manage your Crypto assets, signing transactions and message verification and enhance security.&lt;/p&gt;

&lt;p&gt;Prerequisite: EVM, Blockchain, JavaScript, React.js&lt;/p&gt;

&lt;h2&gt;
  
  
  Check if any EVM based wallet is installed in your browser
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; if (typeof window.ethereum !== "undefined") {
      console.log("Wallet installed");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Check installed wallet is Metamask or not
&lt;/h2&gt;

&lt;p&gt;In that case we will use ethereum.isMetaMask to check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (typeof window.ethereum &amp;amp;&amp;amp; ethereum.isMetaMask !== "undefined") {
      console.log("MetaMask Wallet is present");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  If you don't have MetaMask installed
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; if (typeof window.ethereum === "undefined") {
      console.log("MetaMask Wallet not installed");
      window.location.href = "https://metamask.io/download.html";
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Now we have installed MetaMask, its time to connect the wallet with our website.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    try {
      const accounts = await ethereum.request({
        method: "eth_requestAccounts",
      });
      console.log(accounts);
    } catch (error) {
      console.error(error);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are all the methods we need to follow to connect our wallet with our frontend.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Decentralized Voting App (dApp) Tutorial. Web3 and Blockchain Project.</title>
      <dc:creator>Sourin🥑 | Web 3.0 &amp; Blockchain🚀</dc:creator>
      <pubDate>Sun, 21 May 2023 06:31:42 +0000</pubDate>
      <link>https://dev.to/heysourin/decentralized-voting-app-dapp-tutorial-web3-project-1l4a</link>
      <guid>https://dev.to/heysourin/decentralized-voting-app-dapp-tutorial-web3-project-1l4a</guid>
      <description>&lt;p&gt;Decentralized applications (DApps) are transforming various industries, bringing security, transparency, and trust to the world. One field where the potential of decentralized technology truly shines is in voting systems. By leveraging blockchain technology, decentralized voting application can be created that ensures the integrity of the voting process, removes the need for intermediaries, and empowers every individual with their voting rights.&lt;/p&gt;

&lt;p&gt;In this comprehensive tutorial, we will create our own decentralized voting application from scratch. This guide will provide you with the knowledge and tools you need to get started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisite-Knowledge&lt;/strong&gt;: JavaScript, React.js, Solidity, Ethereum&lt;/p&gt;

&lt;p&gt;But, do not worry if you don’t have the above mentioned knowledges. You can just follow along.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; We will create our Solidity smart contract&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity 0.8.11;

contract Election {
    struct Candidate {
        uint256 id;
        string name;
        uint256 voteCount;
    }

    address public owner;

    mapping(uint256 =&amp;gt; Candidate) public candidates;
    mapping(address =&amp;gt; bool) public voters;

    uint256 public candidataCount;

    constructor() {
        owner = msg.sender;
        addCandidate("Ryle");
        addCandidate("Max");
    }

    function addCandidate(string memory _name) public{
        require(msg.sender == owner, "Only owner can add candidates");
        candidataCount++;
        candidates[candidataCount] = Candidate(candidataCount, _name, 0);
    }

    function vote(uint256 _candidateId) public {
        require(!voters[msg.sender], "You have already voted");
        require(
            _candidateId &amp;lt;= candidataCount &amp;amp;&amp;amp; _candidateId &amp;gt;= 1,
            "Invalid candidate Id"
        );
        voters[msg.sender] = true;
        candidates[_candidateId].voteCount++;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; We will deploy our smart contract on test network. We will get ABI and Contract Address when we deploy our smart contracts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Now we will create our Next.js Application in our local machine by &lt;em&gt;npx create-next-app my-app&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: **In the **index.js&lt;/strong&gt; write this file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Head from "next/head";
import Image from "next/image";
import styles from "../styles/Home.module.css";
import React, { useState, useEffect } from "react";
import { ethers } from "ethers";
import { contractABI, contractAddress } from "./Engine";
import Navbar from "./Navbar";

export default function Home() {
  const [candidatesUseState, setCandidatesUseState] = useState([]);
  const [voters, setVoters] = useState([]);
  const [account, setCurrentAccount] = useState();
  const [walletAddress, setWalletAddress] = useState("");
  const [votedOrNot, setVotedOrNot] = useState();
  const [candidateId, setCandidateId] = useState();

  const checkIfWalletIsConnected = async () =&amp;gt; {
    try {
      const { ethereum } = window;

      if (!ethereum) {
        console.log("Please install metamask!!!");
      } else {
        // console.log("We have the ethereum object", ethereum);
      }

      const accounts = await ethereum.request({ method: "eth_accounts" });
      if (accounts.length) {
        const account = accounts[0];
        // console.log("Authorized account has found", account);
        setCurrentAccount(account);
        console.log("Connected");
      } else {
        setCurrentAccount("");
        console.log("No authorized account has found!");
      }
    } catch (error) {
      console.error(error);
    }
  };

  const connectWallet = async () =&amp;gt; {
    try {
      const { ethereum } = window;

      if (!ethereum) {
        alert("Metamask has found!");
        return;
      }

      const accounts = await ethereum.request({
        method: "eth_requestAccounts",
      });

      // console.log("Connected", accounts[0]);
      // setCurrentAccount(accounts[0]);
    } catch (err) {
      console.error(err.message);
    }
  };

  const getCandidates = async (candidateId) =&amp;gt; {
    const provider = new ethers.providers.Web3Provider(window.ethereum);

    const connection = new ethers.Contract(
      contractAddress,
      contractABI,
      provider
    );

    const candidatesCount = Number(await connection.candidataCount());
    console.log(candidatesCount);

    for (var i = 1; i &amp;lt;= candidatesCount; i++) {
      const candidate = await connection.candidates(i);

      const id = candidate[0];
      const name = candidate[1];
      const voteCount = candidate[2];

      const item = {
        id: Number(id),
        name: name.toString(),
        voteCount: voteCount.toNumber(),
      };
      setCandidatesUseState((prev) =&amp;gt; [...prev, item]);
    }
    // console.log(candidatesUseState);
  };

  const checkVotingStatus = async (voter) =&amp;gt; {
    try {
      const provider = new ethers.providers.Web3Provider(window.ethereum);

      const connection = new ethers.Contract(
        contractAddress,
        contractABI,
        provider
      );

      const hasVoted = await connection.voters(voter);
      console.log(voter, "hasVoted: ", hasVoted);
      setVotedOrNot(hasVoted);
    } catch (error) {
      console.error(error);
    }
  };

  const changeHandler = (e) =&amp;gt; {
    setWalletAddress(e.target.value);
  };

  const handleButtonClick = async () =&amp;gt; {
    await checkVotingStatus(walletAddress);
  };

  const vote = async (candidateId) =&amp;gt; {
    try {
      const provider = new ethers.providers.Web3Provider(window.ethereum);
      const signer = await provider.getSigner();

      const connection = new ethers.Contract(
        contractAddress,
        contractABI,
        signer
      );

      const vote = await connection.vote(candidateId);
    } catch (error) {
      console.error(error);
    }
  };

  const handleChange2 = (e) =&amp;gt; {
    setCandidateId(e.target.value);
  };

  const buttonClick2 = () =&amp;gt; {
    vote(candidateId);
  };

  useEffect(() =&amp;gt; {
    checkIfWalletIsConnected();
    connectWallet();
    getCandidates();
  }, []);

  return (
    &amp;lt;div className=""&amp;gt;
      &amp;lt;Head&amp;gt;
        &amp;lt;title&amp;gt;Voting Dapp ~ heysourin&amp;lt;/title&amp;gt;
        &amp;lt;meta name="description" content="Generated by create next app" /&amp;gt;
        &amp;lt;link rel="icon" href="/icon.png" /&amp;gt;
      &amp;lt;/Head&amp;gt;

      &amp;lt;main className=""&amp;gt;
        &amp;lt;Navbar account={account} connectWallet={connectWallet} /&amp;gt;

        &amp;lt;h1 className="font-bold text-3xl m-5"&amp;gt;Candidates:&amp;lt;/h1&amp;gt;
        &amp;lt;div className="flex flex-row"&amp;gt;
          &amp;lt;table className="w-full border-collapse mx-10"&amp;gt;
            &amp;lt;thead&amp;gt;
              &amp;lt;tr&amp;gt;
                &amp;lt;th className="py-2 px-4 border"&amp;gt;Candidate Id&amp;lt;/th&amp;gt;
                &amp;lt;th className="py-2 px-4 border"&amp;gt;Candidate Name&amp;lt;/th&amp;gt;
                &amp;lt;th className="py-2 px-4 border"&amp;gt;Vote Count&amp;lt;/th&amp;gt;
              &amp;lt;/tr&amp;gt;
            &amp;lt;/thead&amp;gt;
            &amp;lt;tbody&amp;gt;
              {candidatesUseState.map((candidate, i) =&amp;gt; (
                &amp;lt;tr key={i}&amp;gt;
                  &amp;lt;td className="py-2 px-4 border"&amp;gt;{candidate.id}&amp;lt;/td&amp;gt;
                  &amp;lt;td className="py-2 px-4 border"&amp;gt;{candidate.name}&amp;lt;/td&amp;gt;
                  &amp;lt;td className="py-2 px-4 border"&amp;gt;{candidate.voteCount}&amp;lt;/td&amp;gt;
                &amp;lt;/tr&amp;gt;
              ))}
            &amp;lt;/tbody&amp;gt;
          &amp;lt;/table&amp;gt;
        &amp;lt;/div&amp;gt;

        {/* @note CHECK IF VOTED*/}
        &amp;lt;div&amp;gt;
          &amp;lt;h2 className="font-bold text-3xl mt-10 ml-5"&amp;gt;Check Voted or Not:&amp;lt;/h2&amp;gt;
          &amp;lt;div className="flex flex-row mx-10"&amp;gt;
            &amp;lt;input
              type="text"
              className="border border-gray-300 px-4 m-4"
              placeholder="Enter wallet address"
              value={walletAddress || ""}
              onChange={changeHandler}
            /&amp;gt;
            &amp;lt;button
              onClick={handleButtonClick}
              className="bg-gradient-to-r from-orange-600 to-yellow-500 text-white font-bold py-2 px-4 rounded m-4"
            &amp;gt;
              Check if voted
            &amp;lt;/button&amp;gt;
            &amp;lt;div className="mt-6"&amp;gt;
              {votedOrNot ? (
                &amp;lt;p&amp;gt;You have already voted, can not vote anymore!&amp;lt;/p&amp;gt;
              ) : (
                &amp;lt;p&amp;gt;You have not voted yet!&amp;lt;/p&amp;gt;
              )}
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div&amp;gt;
          &amp;lt;h2 className="font-bold text-3xl mt-8 ml-5"&amp;gt;Vote: &amp;lt;/h2&amp;gt;
          &amp;lt;div className="flex flex-row mx-10"&amp;gt;
            &amp;lt;input
              type="text"
              className=" w-24 mx-3 my-4 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
              pattern="\d{0,2}"
              maxLength="2"
              placeholder="Candidate Id"
              value={candidateId || ""}
              onChange={handleChange2}
              required
            /&amp;gt;
            &amp;lt;button
              onClick={buttonClick2}
              className="bg-gradient-to-r from-purple-700 to-blue-500 text-white font-bold py-2 px-4 rounded m-4"
            &amp;gt;
              Vote
            &amp;lt;/button&amp;gt;
            &amp;lt;div className="mt-6"&amp;gt;&amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/main&amp;gt;

      &amp;lt;footer className="flex items-center justify-between bg-gradient-to-r from-gray-900 to-gray-700 p-6 text-white"&amp;gt;
        &amp;lt;a
          href="https://github.com/heysourin"
          target="_blank"
          className="text-left"
        &amp;gt;
          My Github
        &amp;lt;/a&amp;gt;
        &amp;lt;a
          href="https://linkedin.com/in/heysourin"
          target="_blank"
          className="text-left"
        &amp;gt;
          My LinkenIn
        &amp;lt;/a&amp;gt;
        &amp;lt;span className="text-right"&amp;gt;
          &amp;lt;a
            href="https://github.com/heysourin/Voting-dApp-on-Avalanche-Network"
            className="text-white"
          &amp;gt;
            Source Code
          &amp;lt;/a&amp;gt;
        &amp;lt;/span&amp;gt;
      &amp;lt;/footer&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above file has Navbar component import. Create a file &lt;strong&gt;Navbar.jsx&lt;/strong&gt; in the pages folder. Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { React } from 'react'

const Navbar = ({ account, connectWallet }) =&amp;gt; {
  return (
    &amp;lt;nav className="flex items-center justify-between flex-wrap bg-gradient-to-r from-gray-900 to-gray-700 p-6"&amp;gt;
      &amp;lt;div className="flex items-center flex-shrink-0 text-white mr-6"&amp;gt;
        &amp;lt;span className="font-bold text-3xl tracking-tight"&amp;gt;
          Web3 Voting DAPP
        &amp;lt;/span&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div className="flex"&amp;gt;
        {account ? (
          &amp;lt;button
            type="button"
            className='className="bg-gradient-to-r from-blue-500 to-blue-700 text-white py-2 px-4 rounded-m font-bold'
          &amp;gt;
            {account.slice(0, 6) + '...' + account.slice(38, 42)}
          &amp;lt;/button&amp;gt;
        ) : (
          &amp;lt;button
            type="button"
            className='className="bg-blue-500 bg-blue-700 text-white font-bold py-2 px-4 rounded"'
            onClick={connectWallet}
          &amp;gt;
            Connect Wallet
          &amp;lt;/button&amp;gt;
        )}
      &amp;lt;/div&amp;gt;
    &amp;lt;/nav&amp;gt;
  )
}

export default Navbar

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you are good to go :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/heysourin/Voting-dApp-on-Avalanche-Network"&gt;GitHub&lt;/a&gt; repo to refer.&lt;/p&gt;

&lt;p&gt;If you need any help, feel free to &lt;a href="https://linktr.ee/heysourin"&gt;connect&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
