Questions tagged [shellcheck]

Shellcheck refers to the ShellCheck program.

ShellCheck is a tool for linting shell scripts. It works in the browser or can be installed locally.

References

60 questions
3
votes
1 answer

SC2207 Bash array assignment from subshell not splitting as expected

I have been populating an array using: AWS_STS_CREDS=( $(aws sts ...) ) This raises shellcheck error SC2207 Prefer mapfile or read -a to split command output But the recommendation does not work as expected. IFS=" " read -r -a AWS_STS_CREDS <<<…
beanaroo
  • 506
  • 1
  • 5
  • 14
3
votes
3 answers

How to portability use "${@:2}"?

On Allow for ${@:2} syntax in variable assignment they say I should not use "${@:2}" because it breaks things across different shells, and I should use "${*:2}" instead. But using "${*:2}" instead of "${@:2}" is nonsense because doing "${@:2}" is…
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
3
votes
1 answer

Bash script command and getting rid of shellcheck error SC2181

I have the following bash script: dpkg-query --show --showformat='${Status}\n' "$i" 2> \ /dev/null | grep "install ok installed" &> /dev/null if [[ $? -eq 0 ]]; then l_var_is_desktop="true" fi and the ShellCheck utility…
Kris
  • 363
  • 3
  • 11
3
votes
1 answer

ShellCheck warning: "Remove surrounding $() to avoid executing output. [SC2091]"

I have the following set of commands in my script: message="Secure copying file $remoteHost" backupLogOutput "Info $message" $(scp "$file" "$remoteUser"@"$remoteHost":"$remotePath") >> "$BACKUPLOG" backupErrorHandler "$?" "$message" ShellCheck is…
AndyM
  • 562
  • 4
  • 22
3
votes
1 answer

Static code analysis using ShellCheck for shell script - predefined rules

I am trying to use Shellcheck for doing static code analysis for shell scripts. I want to know the rules used to perform the analysis. Where can I get them? Below is the sample output I got for simple helloworld program: In…
Rajeswari
  • 71
  • 2
  • 11
3
votes
2 answers

How is a shellscript syntax checker invoked (by/with syntastic and pathogen)?

When I work on a bash/sh script, pathogen kicks in and correctly loads everything that's in ~/.vim/bundle/syntastic/syntax_checkers/sh/. I checked with :scriptnames in command-line mode. Included are shellcheck.vim, checkbashism.vim, bashate.vim…
Cbhihe
  • 511
  • 9
  • 24
2
votes
0 answers

PowerShell equivalent of Shellcheck

I found this https://github.com/PoshCode/PowerShellPracticeAndStyle but I was wondering if there's anything like shellcheck but for PowerShell.
mikeytown2
  • 1,744
  • 24
  • 37
2
votes
1 answer

In bash, replace each character of a string with a fixed character ("blank out" a string)

MWE: caption() { echo "$@" echo "$@" | sed 's/./-/g' # -> SC2001 } caption "$@" I'd like to use parameter expansion in order to get rid of the shellcheck error. The best idea I had was to use echo "${@//?/-}", but this does not replace…
Johannes
  • 2,901
  • 5
  • 30
  • 50
2
votes
2 answers

Record shellcheck findings in Jenkins

I'm looking for a way to record violation findings of shellcheck in my Jenkins Pipeline script. I was not able to find something so far. For other tools (Java, Python), I'm using Warnings Next Generation, but it does not seem to support shellcheck,…
schilli
  • 1,700
  • 1
  • 9
  • 17
2
votes
1 answer

Best way of using `env` command and passing environment variables by file

We currently have a command for setting the environment for only the following arguments/commands. The environment variables are set by a file, through a simple cat command: env $(cat "$1") However, shellcheck seems to mark…
nkmol
  • 8,025
  • 3
  • 30
  • 51
2
votes
0 answers

shellcheck on sonarcloud (plugin)

I use ShellCheck in order to validate my bash scripts. I have a project that is made in bash and I want to scan it with ShellCheck in SonarCloud. When I use SonarCloud für analysis it shows The main branch has no lines of code.. Currently, I…
dan1st
  • 12,568
  • 8
  • 34
  • 67
2
votes
1 answer

Bash script set Coordinate Universal Time on remote system using ssh and date

I have a bash script that attempts to synchronize the time on another machine. It is not my source code, but as I am refactoring bash script, I am trying to get it to pass ShellCheck. The source code for it looks something like this: d=$(date -u…
Kris
  • 363
  • 3
  • 11
2
votes
0 answers

Parse Shellcheck output in Eclipse problems view

I'm working on a mixed language integration project involving copious amounts of Bash. We use Eclipse as our IDE due to its tight integration with our SCM (not Git). I have successfully configured a builder to run shellcheck against bash code and…
Chris
  • 414
  • 3
  • 12
2
votes
1 answer

Cannot figure out how to fix shellcheck complaint that I should not use a glob as a command when starting one script from another

Example script: #!/bin/bash printf '1\n1\n1\n1\n' | ./script2*.sh >/dev/null 2>/dev/null Shellcheck returns the following: In script1.sh line 3: printf '1\n1\n1\n1\n' | ./script2*.sh >/dev/null 2>/dev/null ^-- SC2211: This…
Harold Fischer
  • 279
  • 1
  • 9
2
votes
1 answer

make sees different PATH than account's .bashrc-configured PATH

I want to call ShellCheck, a Haskell program for linting shell scripts, from a Makefile. When I install ShellCheck via cabal install, it is installed as ~/.cabal/bin/shellcheck. So, I have configured Bash accordingly: $ cat ~/.bashrc export…
mcandre
  • 22,868
  • 20
  • 88
  • 147