A single line comment is written using a #.
#! /bin/bash
# This is a single line comment
echo "Hello world" # This is also a comment
<aside>
📌 The name of a variable can contain only letters (a to z or A to Z), numbers (0 to 9) or the underscore character (_). Also, the variable name cannot start with a number.
</aside>
Created and maintained by the Linux/Unix OS.
Conventionally these are written using uppercase.
Examples of system variables -
#! /bin/bash
echo "Location of bash : $BASH"
echo "Bash Version : $BASH_VERSION"
echo "Path to the home directory (/home/user) : $HOME"
echo "Present working directory : $PWD"
$ ./system-variables.sh
Location of bash (/bin/bash) : /bin/bash
Bash Version : 4.4.20(1)-release
Path to the home directory (/home/user) : /home/shathin
Present working directory : /mnt/g/Dev/Linux-Subsystem/shell-scripting
Created by the user.
Conventionally these are writting using lowercase.
Defining and echoing a variable
#! /bin/bash
my_var=10 # don't put a whitespace on either side of equal symbol (=)
echo The value is $my_var
$ ./user-defined-variable.sh
The value is 10
The unset command can be used to delete a variable.
Example:
#! /bin/bash
my_var=10
echo "Value: $my_var"
unset my_var
echo "Value: $my_var"
$ ./delete-variables.sh
Value: 10
Value:
array_var=(val1 val2 ... valn).$array_var[index]