shellcheck
                                
                                 shellcheck copied to clipboard
                                
                                    shellcheck copied to clipboard
                            
                            
                            
                        SC1017 not excluded properly with .shellcheckrc
- Rule Id
- SC1017
 
- My shellcheck version (shellcheck --versionor "online"):
shellcheck-stable.exe --version
ShellCheck - shell script analysis tool
version: 0.7.0
license: GNU General Public License, version 3
website: https://www.shellcheck.net
- [x] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- [ ] ~I tried on shellcheck.net and verified that this is still a problem on the latest commit~
- Not possible, related to how shellcheck is processing excludes
 
I have a script:
#!/bin/bash
set -$-ue${DEBUG+xv}
echo "hello world"
Git forces by default \r\n on all lines.
I have a .shellcheckrc file with:
# Turn on warnings for unquoted variables with safe values
enable=quote-safe-variables
# Turn on warnings for unassigned uppercase variables
enable=check-unassigned-uppercase
# Allow \r\n as we're on Windows and git by default forces \r\n
disable=SC1017
When I run shellcheck-stable.exe I get:
shellcheck-stable.exe .\test.bash
In .\test.bash line 1:
#!/bin/bash
           ^-- SC1017: Literal carriage return. Run script through tr -d '\r' .
In .\test.bash line 2:
set -$-ue${DEBUG+xv}
         ^---------^ SC2154: DEBUG is referenced but not assigned.
For more information:
  https://www.shellcheck.net/wiki/SC1017 -- Literal carriage return. Run scri...
  https://www.shellcheck.net/wiki/SC2154 -- DEBUG is referenced but not assig...
If I add the exclude to the command line it works properly:
shellcheck-stable.exe .\test.bash
In .\test.bash line 1:
#!/bin/bash
           ^-- SC1017: Literal carriage return. Run script through tr -d '\r' .
In .\test.bash line 2:
set -$-ue${DEBUG+xv}
         ^---------^ SC2154: DEBUG is referenced but not assigned.
For more information:
  https://www.shellcheck.net/wiki/SC1017 -- Literal carriage return. Run scri...
  https://www.shellcheck.net/wiki/SC2154 -- DEBUG is referenced but not assig...
Furthermore, if I change the file to be:
#!/bin/bash
#
#
#
set -$-ue${DEBUG+xv}
echo "hello world"
Shell check says:
shellcheck-stable.exe .\test.bash
In .\test.bash line 1:
#!/bin/bash
           ^-- SC1017: Literal carriage return. Run script through tr -d '\r' .
In .\test.bash line 2:
#
 ^-- SC1017: Literal carriage return. Run script through tr -d '\r' .
In .\test.bash line 3:
#
 ^-- SC1017: Literal carriage return. Run script through tr -d '\r' .
In .\test.bash line 4:
#
 ^-- SC1017: Literal carriage return. Run script through tr -d '\r' .
In .\test.bash line 5:
set -$-ue${DEBUG+xv}
         ^---------^ SC2154: DEBUG is referenced but not assigned.
For more information:
  https://www.shellcheck.net/wiki/SC1017 -- Literal carriage return. Run scri...
  https://www.shellcheck.net/wiki/SC2154 -- DEBUG is referenced but not assig...
So it appears the .shellcheckrc file is only taking affect after the first line which doesn't start with #
I have the same issue, I can't disable this check, and it's very annoying, since it seems to be a false positive.
Hello, I have a problem that where SC1017 is flagged by mistake on comments in the script as well. I fixed it by converting the .shellcheckrc itself to LF line endings. My guess is that when the dotfile configuration itself has CRLF line endings its doesnt process the shell scripts correctly.
I use VS Code with shellcheck plugin v0.37.1 and I can confirm @mevalba tip is working. Thanks.
But be sure to close and reopen the .sh files to have shellcheck recheck the file using the corrected .shellcheckrc
Also this tip fixes another problem when you do not want SC1017 to be disabled and get the SC1017 error on all first lines of all .sh files, even when these has LF line endings.!
Using Windows line ending in a shell file is just a bad habit.
Git doesn't force anything, you just have to configure it with *.bash text eol=lf inside .gitattributes in your repo.
Although most shell on Windows support \r\n inside scripts, this isn't really required and they can also break on these cases.