I
I
Ilya Trusov2016-02-12 18:15:22
bash
Ilya Trusov, 2016-02-12 18:15:22

How to write to a file not just a string?

Hello. You need to write some data to the file, namely the code. I do this:
echo "code" > file
Everything is fine if there is just a string, but when I try to write php code to a file, nothing happens. I thought to transfer to base64, and then decode it, but I'm not sure that there is no more correct way.
Tell me what to do. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2016-02-12
@artgrosvil

#!/bin/bash

myvar=foobuzz

cat <<EOF >> my_template

# my text
$myvar # вставить значение $myvar

EOF

echo "! Вместо переменной сейчас ее значение"
cat my_template


cat <<'EOF' >> my_copypaste

# my text
$myvar # текст

EOF

echo "! Переменная не заменена на ее значение"
cat my_copypaste

! Вместо переменной сейчас ее значение

# my text
foobuzz # вставить значение foobuzz

! Переменная не заменена на ее значение

# my text
$myvar # текст

V
Viktor Taran, 2016-02-12
@shambler81

just don't forget to escape some characters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question