Änderungen

DCEM's bash script howto

771 Byte hinzugefügt, 12:20, 8. Jan. 2020
/* using here-documents */
To create or append to a config file i like to use here-documents.
create files with <code style="white-space: nowrap">></code>, expand files with ">>" after cat
<code>cat > /destination/file.ext << EOF
cat > /destination/file.ext << 'EOF' #
'EOF' is quoted Using a here-document with <code style="white-space: nowrap"> the lines -</code> would allow you to remove tabs to have a nice indentation in the here-document are script, but I'm not expandedusing tags for indentation.  create files with <code style="white-space: nowrap">></code>, expand files with <code style="white-space: nowrap">>></code>, after cat ==== expansions: on - EOF needs to be unquoted ====
EOF is unquoted => all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion, the character sequence \newline is ignored, and ‘\’ must be used to quote the characters ‘\’, ‘$’, and ‘`’.
<code>
cat > /etc/nginx/snippets/letsencrypt.conf << EOF
ssl_certificate /etc/letsencrypt/live/$(hostname)/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$(hostname)/privkey.pem;
EOF
</code>
<code style="white-space: nowrap">$(hostname)</code> will be expanded
==== expansions: off - EOF needs to be quoted ===='EOF' is quoted => the lines in the here-document are not expanded<code>cat >> /etc/nginx/conf.d/seafile.conf << EOF # 'EOF' is quoted => expansions: off location / { proxy_set_header Host $host;</code> [...] }EOF</code><code style="white-space: nowrap">$host</code>will not be expanded
610
Bearbeitungen