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
1
vote
1 answer

SC1091: Not following: ../.sh was not specified as input

What is the best practice to source a local bash file? I get the following shellcheck error on my bash script as it can't follow the path provided in the source: Code snippet that gives the formatting error: source…
Usama Ijaz
  • 31
  • 2
1
vote
2 answers

Shellcheck suggestion for SC2806 giving me issue with JAVA_OPTS

I'm getting shellcheck suggestion SC2806 i.e. Double quote to prevent globbing and word splitting for $JAVA_OPTS. When I apply that to my code java $JAVA_OPTS -Dhttps.proxyHost=%PROXY_HOST% I get the 503 Error Back-end server busy error. The ec2…
SK16
  • 623
  • 8
  • 17
1
vote
1 answer

resolving shellcheck printf warnings have me stuck with either SC2059 or SC2089

For the following code, I'm getting SC2089 "Quotes/backslashes will be treated literally, use an array" # Quotes/backslashes will be treated literally, use an array CMD_AVAIL_MSG='%s is required for this script but the "%s" command is missing.…
mindfullsilence
  • 344
  • 9
  • 23
1
vote
2 answers

how to expand bash function parameters inside function / fix shellcheck SC2294

Assume a function that runs a command in another directory: sub() { cd subdirectory eval "$@" || exit } I would like to be able to invoke this function with parameters that are expanded inside the subdirectory, e.g. sub ls '$(basename…
rethab
  • 7,170
  • 29
  • 46
1
vote
1 answer

Codacy analyzer warning: In POSIX sh, [[ ]] is undefined

When I run codacy-analysis-cli analyze command for the next line of script: if [[ "$lexer_date" > "$lexer_ts_date" ]]; then generate_grammar fi I got the next warning: Found [Warning] `In POSIX sh, [[ ]] is undefined.` in scripts/grammar.sh:20…
Nizami
  • 35
  • 8
1
vote
4 answers

How can I satisfy shellcheck without causing script failure?

I am currently testing out GitHub Actions and the quickstart explains how to add super-linter to a repo which is an easy way to apply linting across a whole repo - I like this idea so I have added it to my repo, one of the linters it applies is…
jamiet
  • 10,501
  • 14
  • 80
  • 159
1
vote
4 answers

Execute command that results from execution of a script whose name is in a variable

When posting this question originally, I totally misworded it, obtaining another, reasonable but different question, which was correctly answered here. The following is the correct version of the question I originally wanted to ask. In one of my…
Enlico
  • 23,259
  • 6
  • 48
  • 102
1
vote
1 answer

Optionally include a user and password in curl request?

I am optionally including a user and password in a curl request as follows: declare creds="" if [ -n "$user" ] && [ -n "$password" ]; then creds="-u ${user}:${password}" fi output=$(curl ${creds} -X PUT -v --write-out "%{http_code}" "$url" \ …
rmf
  • 625
  • 2
  • 9
  • 39
1
vote
2 answers

How to properly format an 'if' statement being passed to a remote server in a when using 'while read'?

Ubuntu 18 Bash 4.4.0 I am wanting to pass an if statement to see whether or not a directory exist. If it does, I want to some commands and then a file. I have read through the similar posts but shellcheck complains about my formatting. …
Vituvo
  • 1,008
  • 1
  • 9
  • 29
1
vote
2 answers

GNU Parallel with shellcheck on multiple files

How do I use GNU Parallel to run shellcheck on all *.sh with a wrapper function? This attempt has the correct target files, but Parallel seems to struggle with the subshell. lint:sh() { local output targets=$(find . -name '*.sh' -exec echo {}…
Tom
  • 981
  • 11
  • 24
1
vote
2 answers

Rewrite bash command to be ShellCheck compliant

How can I rewrite the following bash command to be ShellCheck compliant? memory=$(cat /proc/meminfo | grep 'MemTotal:' | awk {'print $2}' 2> /dev/null) It is currently complaining about: Useless cat. Consider 'cmd < file | ..' or 'cmd file |…
Justin
  • 42,716
  • 77
  • 201
  • 296
1
vote
2 answers

Iterate over specific files in a directory using Bash find

Shellcheck doesn't like my for over find loop in Bash. for f in $(find $src -maxdepth 1 -name '*.md'); do wc -w < "$f" >> $path/tmp.txt; done It suggests instead: 1 while IFS= read -r -d '' file 2 do 3 let count++ 4 echo "Playing file…
denten
  • 691
  • 1
  • 6
  • 15
0
votes
0 answers

How to quote a shell command containing a quote

I'm struggling to fix the following shellcheck warning, because it would require nested quotes: here=$(dirname $(realpath "$0" 2> /dev/null || grealpath "$0")) ^-- SC2046 (warning): Quote this to prevent word splitting. How could I…
PiRK
  • 893
  • 3
  • 9
  • 24
0
votes
0 answers

SC2153 (info): Possible misspelling: CA_PRIVATE_KEY_FILENAME may not be assigned

Context In a project I have two files in: src/ssl_certs/make_ssl_project_certs.sh src/ssl_certs/make_ssl_root_certs.sh The make_ssl_project_certs.sh contains the global variables for those two scripts (along with some documentation). A large…
a.t.
  • 2,002
  • 3
  • 26
  • 66
0
votes
1 answer

shellcheck only enable single rule

shellcheck currently yields a lot of errors when analyzing one of my scripts. To get an overview I'd like to go through each error one by one. Is there a way I can disable all rules but one when using shellcheck?
Philippe
  • 1,715
  • 4
  • 25
  • 49