mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2294 (markdown)
@@ -33,7 +33,7 @@ Let's say you invoke `check sed -i '$d' "my file.txt"`:
|
||||
|
||||
Note that while `"$@"` is essentially always better than `eval "$@"`, it's easy to unintentionally introduce a dependency on bad behavior through the shell debugging anti-strategy of "adding quotes until it works":
|
||||
|
||||
```
|
||||
```sh
|
||||
# Works with problematic example because of double-escaping, fails with correct example
|
||||
check ls -l "'My File.txt'"
|
||||
|
||||
@@ -47,7 +47,7 @@ The correct example is still better, but the function invocation has to be tweak
|
||||
|
||||
If each of the array elements is a carefully escaped shell command or word, use `*` instead of `@` to explicitly join the elements on spaces which is what would happen anyways:
|
||||
|
||||
```
|
||||
```bash
|
||||
on_exit=(
|
||||
'rm /tmp/myfile; '
|
||||
'echo "Finished on $(date)" > log.txt; '
|
||||
@@ -66,7 +66,7 @@ done
|
||||
|
||||
If you require `eval` for another part of the command, explicitly transform the array into a series of escaped shell words. This ensures that the array elements will `eval` back to themselves:
|
||||
|
||||
```
|
||||
```bash
|
||||
# Assumed to be outside of our control,
|
||||
# otherwise we would output this in an array as well:
|
||||
COMMAND='dialog --menu "Choose file:" 15 40 4'
|
||||
|
Reference in New Issue
Block a user