shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

shellcheck should ignore multiline literal strings

Open tigerinus opened this issue 3 years ago • 2 comments

For bugs

  • Rule Id (if any, e.g. SC1000): SC2006, SC1009, SC1072
  • My shellcheck version (shellcheck --version or "online"): 0.8.0
  • [ ] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
  • [x] I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit

For new checks and feature suggestions

  • [ ] https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this
  • [x] I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related

Here's a snippet or screenshot that shows the problem:

echo "
.-. .-. .----. .-.    .-.     .---.    .-.  .-.  .---.  .---.  .-.    .----.  
{ {_} | } |__} } |    } |    / {-. \   | {  } | / {-. \ } }}_} } |    } {-. \ 
| { } } } '__} } '--. } '--. \ '-} /   {  /\  } \ '-} / | } \  } '--. } '-} / 
`-' `-' `----' `----' `----'  `---'    `-'  `-'  `---'  `-'-'  `----' `----'                                                                         
"

Here's what shellcheck currently says:

image

Here's what I wanted or expected to see:

The multiple literal should be ignore.

tigerinus avatar Sep 01 '22 16:09 tigerinus

The code is indeed malformed, and Shellcheck rightly complains about it.

$ echo "$BASH_VERSION"
5.1.9(1)-release
$ echo "
> .-. .-. .----. .-.    .-.     .---.    .-.  .-.  .---.  .---.  .-.    .----.  
> { {_} | } |__} } |    } |    / {-. \   | {  } | / {-. \ } }}_} } |    } {-. \ 
> | { } } } '__} } '--. } '--. \ '-} /   {  /\  } \ '-} / | } \  } '--. } '-} / 
> `-' `-' `----' `----' `----'  `---'    `-'  `-'  `---'  `-'-'  `----' `----'                                                                         
> "
bash: command substitution: line 1: unexpected EOF while looking for matching `''
bash: command substitution: line 2: syntax error: unexpected end of file
bash: command substitution: line 1: unexpected EOF while looking for matching `''
bash: command substitution: line 2: syntax error: unexpected end of file
bash: command substitution: line 1: unexpected EOF while looking for matching `''
bash: command substitution: line 2: syntax error: unexpected end of file
bash: command substitution: line 1: unexpected EOF while looking for matching `''
bash: command substitution: line 2: syntax error: unexpected end of file
bash: command substitution: line 1: unexpected EOF while looking for matching `''
bash: command substitution: line 2: syntax error: unexpected end of file
bash: command substitution: line 1: unexpected EOF while looking for matching `''
bash: command substitution: line 2: syntax error: unexpected end of file

.-. .-. .----. .-.    .-.     .---.    .-.  .-.  .---.  .---.  .-.    .----.  
{ {_} | } |__} } |    } |    / {-. \   | {  } | / {-. \ } }}_} } |    } {-. \ 
| { } } } '__} } '--. } '--. \ '-} /   {  /\  } \ '-} / | } \  } '--. } '-} / 
-' ----' ---'    -'  -'-'  ----'                                                  

and also

bash-2.04.0p96-release-2.04$ echo $BASH_VERSION
2.04.0(96)-release
bash-2.04.0p96-release-2.04$ echo "
> .-. .-. .----. .-.    .-.     .---.    .-.  .-.  .---.  .---.  .-.    .----.  
> { {_} | } |__} } |    } |    / {-. \   | {  } | / {-. \ } }}_} } |    } {-. \ 
> | { } } } '__} } '--. } '--. \ '-} /   {  /\  } \ '-} / | } \  } '--. } '-} / 
> `-' `-' `----' `----' `----'  `---'    `-'  `-'  `---'  `-'-'  `----' `----'                                                                         
> "
bash-2.04.0p96-release: command substitution: line 1: unexpected EOF while looking for matching `''
bash-2.04.0p96-release: command substitution: line 2: syntax error: unexpected end of file
bash-2.04.0p96-release: command substitution: line 1: unexpected EOF while looking for matching `''
bash-2.04.0p96-release: command substitution: line 2: syntax error: unexpected end of file
bash-2.04.0p96-release: command substitution: line 1: unexpected EOF while looking for matching `''
bash-2.04.0p96-release: command substitution: line 2: syntax error: unexpected end of file
bash-2.04.0p96-release: command substitution: line 1: unexpected EOF while looking for matching `''
bash-2.04.0p96-release: command substitution: line 2: syntax error: unexpected end of file
bash-2.04.0p96-release: command substitution: line 1: unexpected EOF while looking for matching `''
bash-2.04.0p96-release: command substitution: line 2: syntax error: unexpected end of file
bash-2.04.0p96-release: command substitution: line 1: unexpected EOF while looking for matching `''
bash-2.04.0p96-release: command substitution: line 2: syntax error: unexpected end of file

.-. .-. .----. .-.    .-.     .---.    .-.  .-.  .---.  .---.  .-.    .----.  
{ {_} | } |__} } |    } |    / {-. \   | {  } | / {-. \ } }}_} } |    } {-. \ 
| { } } } '__} } '--. } '--. \ '-} /   {  /\  } \ '-} / | } \  } '--. } '-} / 
-' ----' ---'    -'  -'-'  ----'                                                                         

The issue isn't with the multiple lines; the issue is with backticks that don't contain valid commands.

kurahaupo avatar Sep 03 '22 03:09 kurahaupo

Additionally, a literal string in bash is surround by $'' and not ""

Example: echo $'ls ``'

rockandska avatar Sep 08 '22 21:09 rockandska