Questions tagged [shellcheck]

shellcheck is a tool for automatically detecting shell script problems

Filter by
Sorted by
Tagged with
1
vote
1answer
133 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
1answer
49 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 ...
4
votes
2answers
394 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}" ...
-3
votes
2answers
74 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
3answers
838 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[@...
1
vote
1answer
2k 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 "${...
9
votes
2answers
953 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 ...
1
vote
4answers
801 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 ...
1
vote
1answer
691 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
1answer
207 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
0answers
39 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 ...
12
votes
1answer
3k 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 $...
1
vote
1answer
389 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 $ ...
7
votes
1answer
266 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 ...
1
vote
1answer
157 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 ...
3
votes
2answers
1k 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 ...
-3
votes
3answers
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 ...
3
votes
2answers
388 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? ...
7
votes
1answer
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 ...