This is my script , even after using the export
command not able to use variable outside of the block. Below is the code that i have tried. I also tried other option like declare -x var
, but that is also not working.
Can someone please please comment on this , am i doing right ?
#!/bin/bash
{
var="123"
export var # exporting the variable so that i can access from anywhere
echo "var is "$var # able to get the value of this variable
} | tee log.txt
echo "var is "$var # not able to get the value of this variable