1 what does the variable do Give an example where this valu
1. what does the variable $? do? Give an example where this value is useful, and explain whether it is case-sensitive or not. (Justify your Answers with example by running commands in the Linux machine).
2. Why does echo, $MyVar, quotes, set, unset, $PS1, $PATH, env, export commands are used, give a detailed explanation of it and also Plz run all the commands in the Linux machine. (Everyone should have their own Id’s).
Solution
1. Dollar sign($) is one of the important character generally used in languages which these are used to devolep applications. This dollar sign is a case sensitive and itis followed with the variable so that it shows the value that is present in the variable.
Let us see the example of it wher we use
[rahul@RHELv4u3 ~]$ echo This is the $SHELL shell
This is the /bin/bash shell. we can take this example.
[rahul@RHELv4u3 ~]$ echo Hello $USER
Hello rahul.............. This shows that this is a case sensitive.
2. echo: This command is used to display the value which is present in the variable
example:
#!/bin/sh
MY_MESSAGE=\"Hello World\"
echo $MY_MESSAGE
$MyVar: This command is used to find the functionality of the variable
example:
#!/bin/sh
echo \"MYVAR is: $MYVAR\"
MYVAR=\"hi there\"
echo \"MYVAR is: $MYVAR\"
quotes: The double quotes which allows parsing of the variables whereas single quotes stops from this.
Let us take an example of this:
[rahul@RHELv4u3 ~]$ MyVar=555
[rahul@RHELv4u3 ~]$ echo $MyVar
555
[rahul@RHELv4u3 ~]$ echo \"$MyVar\"
555
[rahul@RHELv4u3 ~]$ echo \'$MyVar\'
$MyVar
These variables are replaced with with their own values in double quotes in bash shell
rahul@laika:~$ city=hyderabad
rahul@laika:~$ echo \"We are in $city today.\"
We are in hyderabad today.
rahul@laika:~$ echo \'We are in $city today.\'
We are in $city today.
set: This command is used to show the environmental variables.
unset: This command is to removce the variables from environmental shell.
example:
[rahul@RHEL4b ~]$ MyVar=6602
[rahul @RHEL4b ~]$ echo $MyVar
6602
[rahul @RHEL4b ~]$ unset MyVar
[rahul @RHEL4b ~]$ echo $MyVar
[rahul @RHEL4b ~]$
$PS1: this commnad is used to finds the shell prompt that you are using
example:
rahul@deb503:~$ PS1=prompt
prompt
promptPS1=\'prompt \'
prompt
prompt PS1=\'> \'
>
> PS1=\'\\u@\\h$ \'
rahul @deb503$
rahul @deb503$ PS1=\'\\u@\\h:\\W$\'
rahul @deb503:~$
$PATH; This command is used to find the shell to tell that what command it is looking to execute.
evample:
[[rahul@RHEL4b ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:
env: This command is used to display the exported values list.
example:
[rahul@RHEL4b ~]$ bash -c \'echo $SHELL $HOME $USER\'
/bin/bash /home/ rahul rahul
[rahul @RHEL4b ~]$ env -i bash -c \'echo $SHELL $HOME $USER\'
/bin/bash
[rahul @RHEL4b ~]$
this command is also used to clean the shell
export: This command is used to export the commands to other shells.
example:
[rahul@RHEL4b ~]$ var3=three
[rahul @RHEL4b ~]$ var4=four
[rahul @RHEL4b ~]$ export var4
[rahul @RHEL4b ~]$ echo $var3 $var4
three four
[rahul @RHEL4b ~]$ bash
[rahul @RHEL4b ~]$ echo $var3 $var4
four


