Comments & Variables | Bash Shell Scripting Tutorial For Beginners | Session -2

preview_player
Показать описание
Bash Shell Scripting For Beginners: Comments & Varibales in Scripting
=========================================================

Comments:
---------

Comments line(s) start with # (pound symbol) which are ignored by the shell.
System doesn't read the commented lines, these are there in files for the help of the users.

Variables:
----------

Variables are the containers which stroes the data like numbers, strings, etc inside them.

Variables are of two types in UNIX like systems:
1. System Variables
2. User Defined Variables

1. System Variables are written & maintained by the developers & are generally defined in CAPTITAL letters.
e.g. HOME, SHELL, HOSTNAME, PWD

# echo $SHELL
# echo $HOSTNAME

2. User Defined Variables are defined, maintained and used by the users.
e.g. MyVar, newvar

# MyVar=55
# echo $MyVar

--------------

$ Dollar Sign:
--------------

Another important character interpreted by the shell is the dollar sign $. The shell will look for an environment variable named like the string following the dollar sign and replace it with the value of the variable (or with nothing if the variable does not exist).
These are some examples using $HOSTNAME, $USER, $UID, $SHELL, and $HOME

Varibales are case sensitive.
# echo Hello $USER
# echo Hello $user

Creating Variables.
# MyVar=666
# echo $MyVar

This will permanently set the value in the variables but defining a variable in script will not set it
permanently, it will clear after the execution of the script.

Variable cannot start with numbers.
# 50var=444

Quotes:
Notice that double quotes still allow the parsing of variables, whereas single quotes prevent
this.
# MyVar=777
# echo $MyVar
777
# echo "$MyVar"
777
# echo '$MyVar'
$MyVar

You can use the set command to display a list of environment variables. On Ubuntu and
Debian systems, the set command will also list shell functions after the shell variables. Use
set | more to see the variables then.

# set | more

Use the unset command to remove a variable from your shell environment.
# echo $MyVar
# unset MyVar
# echo $MyVar
-------------------
We can use both types of variables in our scripts.

#! /bin/bash
echo "Hello World"

# This is a commented line, system will not print during the execution of the script.
echo My shell is $SHELL
echo My shell is $BASH
The version of my shell is $BASH_VERSION
echo My username is $USER
echo I am currently working inside $PWD on $HOSTNAME
---------------------
# User Defined variables
name=VikasNehra
echo My name is $name
Myvar=1000
echo Can I get $Myvar likes on this Youtube Video???

# Variables cannot start with numbers.
5var=100

echo $5var # This will give an error.

echo "If you like this video, please share it with others also."

echo "Please Subscribe To Our Nehra Classes YOUTUBE Channel For More Videos on Bash Shell Scripting."

================================================
Shell Scripting Tutorial For Beginners | Bash Shell Scripting Tutorial | Learn Shell Programming | Nehra Classes

===
Thanks for watching the video. If it helped you then, please do like & share it with others as well. Feel free to post your queries & suggestions, we will be glad to answer your queries.
If you like our hard work then do subscribe to our channel & turn on the bell notification for latest updates.
===
Contact Us:
===
©COPYRIGHT. ALL RIGHTS RESERVED.
Рекомендации по теме
Комментарии
Автор

You deserve 10 Million Subscribers!!
Sir please start a series on Python and Python Boto 3, if possible

chetanarora
Автор

What is the difference between Hostname and terminal?
If asked in an interview?

chetanarora