To create a variable,
variable1 = "uday"
To use it, append dollar in front of it(prefix) and read its value.
echo $person
The unset command can be used to delete a variable:
a=20
echo $a
unset a
the set command will show all variables declared in shell, as well as functions that
have been declared
declare -x variable=value
Here, the declare command with the –x option will make it an environmental
or global variable
the env command will display all environmental variables
Whenever we declare a variable, that variable will be available in the current terminal or shell. This variable will not be available to any other processes, terminal, or shell.
Let's see the effect of $, "", '' and \ on variable behavior:
planet="Earth"
echo $planet
echo "$planet"
echo '$planet'
echo \$planet
Environmental variables are inherited by any subshells or child processes. For example, HOME, PATH. Every shell terminal has the memory area called environment. Shell keeps all details and settings in the environment. When we start a new terminal or shell, this environment is created every time.
We can view environment variables by the following command:
$ env
Or:
$ printenv
If we create a new variable, it will not be available in subshells. The newly created variable will be available only in the current shell. If we run Shell script, then local variables will not be available in the commands called by Shell script. Shell has one special variable $$. This variable contains the process ID of the current shell.
bash #This command will create a new subshell
Using the export command, we are making variables available in the child process or subshell. But if we declare new variables in the child process and export it in the child process, the variable will not be available in parent process. The parent process can export variables to child, but the child process cannot export variables to the parent process.
Whenever we create a Shell script and execute it, a new shell process is created and the Shell script runs in that process. Any exported variable values are available to the new shell or to any subprocess.
We can export any variable as follows:
$ export NAME
Or:
$ declare -x NAME
Let's understand the concept of exporting the variable by the following example:
$ PERSON="Some name"
$ export PERSON
$ echo $PERSON
$ echo $$
The process ID of the current shell or parent shell is one integer.
$ bash
This will start a subshell.
$ echo $$
We can declare variables as read-only using following command read-only:
The usage is as follows:
$ readonly currency=Dollars
Let's try to remove the variable:
$ unset currency
It will give error.
variable1 = "uday"
To use it, append dollar in front of it(prefix) and read its value.
echo $person
The unset command can be used to delete a variable:
a=20
echo $a
unset a
the set command will show all variables declared in shell, as well as functions that
have been declared
declare -x variable=value
Here, the declare command with the –x option will make it an environmental
or global variable
the env command will display all environmental variables
Whenever we declare a variable, that variable will be available in the current terminal or shell. This variable will not be available to any other processes, terminal, or shell.
Let's see the effect of $, "", '' and \ on variable behavior:
planet="Earth"
echo $planet
echo "$planet"
echo '$planet'
echo \$planet
Environmental variables are inherited by any subshells or child processes. For example, HOME, PATH. Every shell terminal has the memory area called environment. Shell keeps all details and settings in the environment. When we start a new terminal or shell, this environment is created every time.
We can view environment variables by the following command:
$ env
Or:
$ printenv
If we create a new variable, it will not be available in subshells. The newly created variable will be available only in the current shell. If we run Shell script, then local variables will not be available in the commands called by Shell script. Shell has one special variable $$. This variable contains the process ID of the current shell.
bash #This command will create a new subshell
Using the export command, we are making variables available in the child process or subshell. But if we declare new variables in the child process and export it in the child process, the variable will not be available in parent process. The parent process can export variables to child, but the child process cannot export variables to the parent process.
Whenever we create a Shell script and execute it, a new shell process is created and the Shell script runs in that process. Any exported variable values are available to the new shell or to any subprocess.
We can export any variable as follows:
$ export NAME
Or:
$ declare -x NAME
Let's understand the concept of exporting the variable by the following example:
$ PERSON="Some name"
$ export PERSON
$ echo $PERSON
$ echo $$
The process ID of the current shell or parent shell is one integer.
$ bash
This will start a subshell.
$ echo $$
We can declare variables as read-only using following command read-only:
The usage is as follows:
$ readonly currency=Dollars
Let's try to remove the variable:
$ unset currency
It will give error.
No comments:
Post a Comment