mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
Created SC2041 (markdown)
25
SC2041.md
Normal file
25
SC2041.md
Normal file
@@ -0,0 +1,25 @@
|
||||
## This is a literal string. To run as a command, use $(seq 1 10)
|
||||
|
||||
### Problematic code:
|
||||
|
||||
for i in 'seq 1 10'
|
||||
do
|
||||
echo "$i"
|
||||
done
|
||||
|
||||
### Correct code:
|
||||
|
||||
for i in $(seq 1 10)
|
||||
do
|
||||
echo "$i"
|
||||
done
|
||||
|
||||
### Rationale:
|
||||
|
||||
The intent was to run the code in the single quotes. This would have worked with slanted backticks, `` `..` ``, but here the very similar looking single quotes `'..'` were used, resulting in a string literal instead of command output.
|
||||
|
||||
This is one of the many problems with backticks, so it's better to use `$(..)` to expand commands.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None.
|
Reference in New Issue
Block a user