2

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.

1 Answer 1

3

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
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=+ASM
EOF

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

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .