Answer the question
In order to leave comments, you need to log in
How to create a file with content in bash if it doesn't exist?
Hello, you need to create several files through sh if they are not there. I try this:
if [ ! -f "/folder/file1.html" ]; then
cat > folder/file1.html << EOF
...........
EOF
fi
if [ ! -f "/folder2/file2.html" ]; then
cat > folder2/file2.html << EOF
...........
EOF
fi
As a result, it writes the first file, but puts
" ...........
EOF
fi
if in the content [ ! -f "/folder2/file2.html" ]; then
cat > folder2/file2.html << EOF
..........."
i.e. does not see the end of the first file, but ends there, where does the content of the second end? How to disconnect from?
Answer the question
In order to leave comments, you need to log in
1. Your script works fine if you copy it from this page. If you add a space after the second EOF
if [ ! -f "/folder/file1.html" ]; then
cat > folder/file1.html << EOF
...........
EOF<здесь пробел>
fi
then your error cat > /folder2/file2.html << EOF
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question