2022 Developer Survey is open! Take survey.

Questions tagged [shellcheck]

shellcheck is a tool for automatically detecting shell script problems

Filter by
Sorted by
Tagged with
5 votes
4 answers
734 views

Shellcheck approved way to pass 2 arguments in one variable, to a command in a bash script

In a bash script, I call another programme, but I want to configure that programme with a command line option. The following works: AREA_ARG="" if __SOME_SETTING__ ; then AREA_ARG=" --...
user avatar
  • 1,049
5 votes
1 answer
836 views

if ! <command> (...) vs. <command> ; if [ $? -eq 0 ] (...)

I am working on a shell script and decided to check my work via shellcheck.net. I am able to get functionally the same behavior of the following two lines in my script: findmnt /dev/sda1 >/dev/null ...
user avatar
  • 1,500
1 vote
1 answer
728 views

how to get user input with a prompt into a variable in a posix compliant way

read -r -p "put an option: " option echo $option this works but shellcheck gives me: In POSIX sh, read -p is undefined. How to get user input with a prompt into a variable in a posix ...
user avatar
-2 votes
1 answer
67 views

ShellCheck warning of individual redirects [closed]

I am using here document to create a startup script, when I checked my code on https://www.shellcheck.net it gives me a warning which it can be ignored. But I am wondering if there is a better way to ...
user avatar
  • 61
4 votes
2 answers
584 views

ShellCheck warning regarding quoting ("A"B"C")

I am writing simple shell script and when I check my script at https://www.shellcheck.net it give me error at line 14 Line 14: sysrc ifconfig_"${Bridge}"="addm ${NIC}" ...
user avatar
  • 61
-3 votes
2 answers
105 views

Why won't || work in a shell script?

# Detect Operating System function dist-check() { # shellcheck disable=SC1090 if [ -e /etc/os-release ]; then # shellcheck disable=SC1091 source /etc/os-release DISTRO=$ID # ...
user avatar
4 votes
3 answers
1k views

What is the difference between double-quoting and not double-quoting an array in Bash?

While tracking down an error in my shellscript, I found the following behavior in this code snippet: declare -a filelist readarray filelist < <(ls -A) readonly filelist for file in "${filelist[@...
user avatar
  • 441
3 votes
1 answer
7k views

Unexpected EOF while looking for matching `"' problem

I need some help figuring out where my code is hitching up. The code is below: servers=( Sanger ) races=( American African Asian) jobbs=( NCBI ) ranges=( 1-2, 2-3, 3-4 ) for server in "${...
user avatar
  • 33
9 votes
2 answers
1k views

ShellCheck is carping that my expression is not in double quotes when it really is; why?

I'm writing a bash script with the AWS CLI and shellcheck is giving an error that I think is incorrect. I'd like to try to figure out why its carping. Here's the code, and error message: for server ...
user avatar
  • 543
1 vote
4 answers
1k views

Bash - print reversed file list using glob

Is there a way to reverse a file list via glob? So I would get the same result as with: ls -r * I'm using this in a shell-script and shellcheck keeps complaining: ^--------^ SC2045: Iterating ...
user avatar
  • 4,760
3 votes
1 answer
1k views

VS Code editor | How to include -x switch for ShellCheck?

Problem description and reproduction In terminal run: shellcheck -x my_script Where my_script sources another (partial) script. I get no error with the -x switch, but if I run it without -x: ...
user avatar
2 votes
1 answer
332 views

Why I have to not quote a string variable in this specific case?

My Ubuntu/Debian-based Linux update POSIX shell script seems to require me not to double quote the string variable with the stored command, which is being executed. As I don't understand this issue, I'...
user avatar
0 votes
0 answers
62 views

Why does running shellcheck from the demo flatpak work, but fail in Atom?

I've installed Atom from flathub. Now using the linter-shellcheck fails and says, the shellcheck command is not available. However, if I use the flatpak demo application and use flatpak enter to ...
user avatar
  • 2,136
15 votes
1 answer
5k views

Bash: What does "masking return values" mean?

shellcheck generated the following warning SC2155: Declare and assign separately to avoid masking return values For this line of code local key_value=$(echo "$current_line" | mawk '/.+=.+/ {print $...
user avatar
1 vote
1 answer
519 views

Define variable using read from stdin of heredoc

I am trying to store Available and Total Memory into variables in a script file as follows, read -r Available Total <<EOT $(free -m | awk '/^Mem/{print $7; print $2;}') EOT $ echo $Total $ ...
user avatar
  • 1,364
7 votes
1 answer
281 views

Unexpected outcome of a="$@"

I'm struggling with this situation: $ set -- 1 2 3 $ a="$@" $ echo "$a" 1 2 3 What I find unexpected is the assignment itself. man bash says this about the "$@" expansion: When the expansion ...
user avatar
1 vote
1 answer
214 views

printf work-alike wrapper for prefixing and redirecting error messages

I have an error function in my POSIX sh shell code. It essentially looks like error () { printf 'utility: ERROR: ' >&2 printf "$@" >&2 } The second printf makes it so that I ...
user avatar
  • 268k
3 votes
2 answers
2k views

shellcheck warns about loops over find output even when given the path to begin search [duplicate]

Ubuntu 16.04 #!/bin/bash site="hello" wDir="/home/websites/${site}/httpdocs/" for file in $(find "${wDir}" -name "*.css") do echo "$file"; done exit 0; shellcheck warns me even if I define the ...
user avatar
-1 votes
3 answers
2k views

"Make sure not to read and write the same file in the same pipeline" [duplicate]

shellcheck reports: echo -e "blah/blah\n$(cat "$tmpdir"/"$filename".jpdf)" > "$tmpdir"/"$filename".jpdf ^-- SC2094: Make sure not to read and write the same file in the ...
user avatar
  • 89.9k
3 votes
2 answers
443 views

Shellcheck complains that I should not to read and write the same file in the same pipeline

ShellCheck show the following error for this line of code: printf '%d' $(($(< "$1") + 1)) > "$1" Make sure not to read and write the same file in the same pipeline Is this really a problem? ...
user avatar
  • 1,732
7 votes
1 answer
2k views

bash shellcheck issue with variables in brace expansion

I'm trying to create an array of file names, based on two variable and using brace expansion, like this: #!/bin/bash altdir=/usr arg=abc tries=({.,$altdir}/{$arg,$arg/main}.{tex,ltx,drv,dtx}) for i ...
user avatar