I have a shell script where i want to print date which is inside a heredoc. Below is the code snippet.
echo "This is a text"
echo I want date to print inside heredoc <<EOF
var1=`date`
echo $var1
EOF
echo "Thats All"
Output of the above code is
I want date to print inside heredoc
Thats All
Its not printing the date. Even if i put any echo command its not printing. What can be wrong here.
NOTE: i tried adding the below in my code for heredoc ___EOF -- Did not work 'EOF' -- Did not work
Please suggest.
This is my actual code when i have to switch to a different user and then perform some operations over there
su - oracle << EOF
echo $(xyz file.prop) > replace.txt
var1=`cat replace.txt_orig`
var2=`cat replace.txt`
echo $var1
echo $var2
EOF
Here the Variable assignment and echo is not working.
$( ... )
for examplevar1=$(date)
. Secondly, double-quote your variables when you use them, soecho "$var1"
. In this particular situation it won't make any visible difference but it's an important habit to gain, so that when it does make a difference you don't get bitten