The Unix "variables", export, read, unset commands

iKnow-IT banner

Variables

  • export command
  • . (dot) command
  • read command
  • unset command

export command

"An example of using variable without exporting"
$ VAR=“This is a variable” 
$ echo $VAR 
This is a variable 
$ ksh 
$ echo $VAR

$ exit 
$ echo $VAR 
This is a variable 
$
"An example of using variable with exporting"
$ VAR=“This is a variable” 
$ export VAR 
$ echo $VAR 
This is a variable 
$ ksh 
$ echo $VAR 
This is a variable 
$ exit 
$ echo $VAR 
This is a variable 
$

. (dot) command

 .. 

 

read command 

read VAR 
echo $VAR

ls | while read X 
do 
     echo My file : $X 
done 

unset command

"unset" removes the content of variable
$ cat test4.sh 
VAR1=no 
echo ${VAR1} 
... 
unset VAR1 
echo ${VAR1} 
$ ./test4.sh 
no
$