Mostra la pàginaRevisions anteriorsQuè hi enllaçaExporta a PDFTorna dalt Aquesta pàgina és només de lectura. Podeu veure'n el codi font, però no podeu canviar-la. Consulteu el vostre administrador si penseu que això és degut a algun error. = heredoc (docs emblebed) un //heredoc// es la manera de "embutir" un documento de texto dentro de un script para volcar a nuestro criterio. == ejemplos el //EOF// usado en los ejemplos no deja de ser una etiqueta, no es mandatory... podríamos usar MITEXTO, la cuestión es definir principio y fin con la misma etiqueta ===sintaxis básica no se permite indentación? <code bash> #!/bin/bash OUT=/tmp/output.txt cat <<EOF Status of backup as on $(date) Backing up files $HOME and /etc/ EOF echo "Starting backup using rsync..." </code> === + indentación natural del doc permite indentación del documento! <code bash> #!/bin/bash OUT=/tmp/output.txt cat <<-EOF Status of backup as on $(date) Backing up files $HOME and /etc/ EOF echo "Starting backup using rsync..." </code> === + no bash expansion <code bash> #!/bin/bash OUT=/tmp/output.txt # No parameter and variable expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word. # If any part of word is quoted, the delimiter is the result of quote removal on word, and the lines in the here-document # are not expanded. So EOF is quoted as follows cat <<'EOF' >$OUT Status of backup as on $(date) Backing up files $HOME and /etc/ EOF </code> resultado: Status of backup as on $(date) Backing up files $HOME and /etc/ === + redirección (también permite >>) <code bash> #!/bin/bash OUT=/tmp/output.txt cat <<EOF >$OUT Status of backup as on $(date) Backing up files $HOME and /etc/ EOF </code> === en memoria! <code bash> #!/bin/bash OUT=/tmp/output.txt ## in memory here docs ## thanks https://twitter.com/freebsdfrau exec 9<<EOF Status of backup as on $(date) Backing up files $HOME and /etc/ EOF ## continue echo "Starting my script..." echo "Doing something..." ## do it cat <&9 >$OUT echo "Starting backup using rsync..." </code> /via: [[https://www.cyberciti.biz/faq/using-heredoc-rediection-in-bash-shell-script-to-write-to-file/]] linux/bash/heredoc.txt Darrera modificació: 23/11/2017 05:10per mate