Questions tagged [shellcheck]

shellcheck is a tool for automatically detecting shell script problems

Filter by
Sorted by
Tagged with
1 vote
1 answer
30 views

Why do I need to disable=SC2031

Can you tell me, why I have to # shellcheck disable=SC2030 in the following script? get_names_and_hosts(){ unset LOCAL_HOSTS declare -a LOCAL_HOSTS unset LOCAL_NAMES declare -a LOCAL_NAMES ...
  • 143
1 vote
1 answer
24 views

POSIX One-Liner For Current Directory - Trying to make it pass ShellCheck

The one-liner from mklement0 in this discussion on POSIX-compliant scripts and getting the full path. It's failing ShellCheck. Removing the space causes it to no longer work. https://stackoverflow....
  • 11
5 votes
4 answers
1k 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=" --...
  • 1,096
5 votes
1 answer
1k 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 ...
  • 1,520
1 vote
1 answer
1k 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 ...
-2 votes
1 answer
80 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 ...
  • 61
4 votes
2 answers
653 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}" ...
  • 61
-3 votes
2 answers
121 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 # ...
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[@...
  • 441
3 votes
1 answer
10k 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 "${...
  • 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 ...
  • 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 ...
  • 4,928
6 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: ...
2 votes
1 answer
393 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'...
0 votes
0 answers
65 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 ...
  • 2,366
16 votes
1 answer
6k 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 $...
's user avatar
1 vote
1 answer
575 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 $ ...
  • 1,384
7 votes
1 answer
287 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 ...
's user avatar
1 vote
1 answer
239 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 ...
  • 282k
4 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 ...
-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 ...
  • 92.7k
3 votes
2 answers
457 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? ...
  • 1,782
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 ...