I am trying to build a file invoked from a script that echoes what is in quotes to a file - only, the $ gets omitted.

This is what I was trying to do:

echo -e "export ORACLE_BASE=/oracle/APP/grid \n 
export ORACLE_HOME=/oracle/APP/grid/12.1.0/grid\n
export PATH=$ORACLE_HOME/bin:$PATH\n export ORACLE_SID=+ASM”>/home/oragrid/ASM.env 

But it doesn't quite echo into the file.


Don't use echo -e in scripts aimed at portability. Use the shell built-in printf() which does everything as the former and still remains compliant across shells. For your requirement though, to store a multi-line string without expanding variables prefixed with $, use a here-doc

cat << 'EOF' > /home/oragrid/ASM.env
export ORACLE_BASE=/oracle/APP/grid
export ORACLE_HOME=/oracle/APP/grid/12.1.0/grid

This would keep all the content within EOF intact, not expanding the variables inside.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.