Syntax highlighting and markdown

Léo Colombaro
2021-10-25 03:11:35 +02:00
parent 1542433c0b
commit 0bcbefb47c

@@ -1,11 +1,14 @@
# Quote this to prevent word splitting # Quote this to prevent word splitting.
### Problematic code: ### Problematic code:
```sh
ls -l $(getfilename) ls -l $(getfilename)
```
### Correct code: ### Correct code:
```sh
# getfilename outputs 1 file # getfilename outputs 1 file
ls -l "$(getfilename)" ls -l "$(getfilename)"
@@ -14,6 +17,7 @@
do do
ls -l "$line" ls -l "$line"
done done
```
### Rationale: ### Rationale:
@@ -27,15 +31,19 @@ If the command substitution outputs multiple pieces of data, use a loop instead.
In rare cases you actually want word splitting, such as in In rare cases you actually want word splitting, such as in
```sh
# shellcheck disable=SC2046 # shellcheck disable=SC2046
gcc $(pkg-config --libs openssl) client.c gcc $(pkg-config --libs openssl) client.c
```
This is because `pkg-config` outputs `-lssl -lcrypto`, which you want to break up by spaces into `-lssl` and `-lcrypto`. This is because `pkg-config` outputs `-lssl -lcrypto`, which you want to break up by spaces into `-lssl` and `-lcrypto`.
A bash alternative in these cases is to use `read -a` for words or `mapfile` for lines. ksh can also use `read -a`, or a `while read` loop for lines. In this case, since `pkg-config` outputs words, you could use: A bash alternative in these cases is to use `read -a` for words or `mapfile` for lines. ksh can also use `read -a`, or a `while read` loop for lines. In this case, since `pkg-config` outputs words, you could use:
```sh
# Read words into an array in bash and ksh # Read words into an array in bash and ksh
read -ra args < <(pkg-config --libs openssl) read -ra args < <(pkg-config --libs openssl)
# expand args # expand args
gcc "${args[@]}" client.c gcc "${args[@]}" client.c
```