Änderungen

Aus Hackerspace Ffm
Wechseln zu: Navigation, Suche

DCEM's bash script howto

949 Byte hinzugefügt, 11:56, 8. Jan. 2020
== Code Style ==
I use bashate as lint tool:
 
[https://github.com/openstack/bashate bashate]
=== Indentations ===
I like to be able to copy and paste parts of a shell script directly to the shell.
 Indentations with tabs will cause problems here, this is why I prefer spaces== Strategy ==I prefer to use command line editors like sed to edit config (or similar) files. This way these edits are scriptable. If there are variables these will be defined as enviromental variables at the beginning of a script. This way it is easy to see what customisations are intended/needed. === 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 << EOFcat > /destination/file.ext << 'EOF' # 'EOF' is quoted => the lines in the here-document are not expandedEOF 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>
610
Bearbeitungen