0

How do I print some text (in this case another bash script) exactly to some output file in bash?

So essentially I want to do something equivalent to the following but with special conditions:

echo [some multiline bash script] > output.bash

and output.bash would contain [some multiline bash script] exactly and no variable substitution occur

shengmin
  • 319
  • 1
  • 3
  • 13
  • 1
    Have a look at [this SO Question](http://stackoverflow.com/q/2953081/205936). – S.R.I Jan 14 '14 at 04:16
  • 1
    Also, you don't want variable interpolation to occur, you can quote the 'Limit String' as shown [here](http://tldp.org/LDP/abs/html/here-docs.html). Look for 'Parameter substitution turned off' or just copy the entire script into `output.bash`. – S.R.I Jan 14 '14 at 04:21

3 Answers3

0
cat [some multiline bash script] > output.bash
rejin
  • 179
  • 1
  • 13
0

print some text to file.name

cat >> file.name <<EOF
# base script 
ls
ls
cd ..
#...
EOF
pexeer
  • 685
  • 5
  • 8
0

use single quote ''

like this '\' is for multi line input

#oyss=2
#echo '$oyss \
> $oyss line 2
> ' > 1.txt

#cat 1.txt
$oyss\
$oyss line 2

if you use double quote "".you will get the variable evaluated.

#echo "$oyss\
> $oyss line 2
> "
22 line 2
oyss
  • 662
  • 1
  • 8
  • 20