Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
2
votes
1
answers
66
views
Shellcheck reporting SC2030 on BATS test description line
I have Shellcheck flagging strange statements when applied to BATS MRE: ``` #!/usr/bin/env bats @test "test descirption" { : } my_function() { api_key=$(jq -r '.key' <<<"$output") } ``` ``` Line 4: @test "test descirption" { ^-- SC2030 (info): Modification of output is local (to subshell caused by @...
I have Shellcheck flagging strange statements when applied to BATS
MRE:
#!/usr/bin/env bats
@test "test descirption" {
:
}
my_function() {
api_key=$(jq -r '.key' <<<"$output")
}
Line 4:
@test "test descirption" {
^-- SC2030 (info): Modification of output is local (to subshell caused by @bats test).
Line 9:
api_key=$(jq -r '.key' <<<"$output")
^-- SC2034 (warning): api_key appears unused. Verify use (or export if used externally).
^-- SC2031 (info): output was modified in a subshell. That change might be lost.
I'm not even modifying the $output
, I'm just reading it. The BATS run
command would be setting it (omitted in MRE).
I also don't understand why would it be reported for the test description line?
There is also SC2031 reported for <<<"$output"
when I'm not modifying it at all.
It seems to be caused by defining a regular function in the BATS file (to handle the repeating part of test cases).
If I move the function into setup()
it makes the findings go away. Yet I'd prefer not to do it.
Doing things in the global scope of BATS test is discouraged but not forbidden.
Defining the function there doesn't seem to break BATS, but it looks like Shellcheck has a problem with it. Why?
Jakub Bochenski
(325 rep)
Jun 13, 2025, 03:14 PM
• Last activity: Jun 14, 2025, 12:41 PM
9
votes
3
answers
4555
views
Who is responsible for providing `set -o pipefail`
I want strict mode in my scripts. I would also appreciate portability. [set -o pipefail](https://www.translucentcomputing.com/2020/11/unofficial-bash-strict-mode-pipefail/) seems compulsory. Yet `shellcheck`(a static linter) is unhappy that "In POSIX sh, set option pipefail is undefined". Is it corr...
I want strict mode in my scripts. I would also appreciate portability.
[set -o pipefail](https://www.translucentcomputing.com/2020/11/unofficial-bash-strict-mode-pipefail/) seems compulsory. Yet
shellcheck
(a static linter) is unhappy that "In POSIX sh, set option pipefail is undefined".
Is it correct? If so, is this a bash
solely feature or is it rather prolific?
Vorac
(3197 rep)
Jun 19, 2021, 07:33 AM
• Last activity: Mar 18, 2025, 04:32 PM
0
votes
1
answers
221
views
ShellCheck does not detect error? How to fix my snippet?
I likely have syntax errors in the following (POSIX) shell snippet: ```sh #!/bin/sh if tput setaf >/dev/null 2>&1; then tput_init_linux else tput_init_none; elif tput AF >/dev/null 2>&1; then tput_init_bsd else tput_init_none; else tput_init_none; fi ``` ShellCheck 0.10.0 does say nothing about it,...
I likely have syntax errors in the following (POSIX) shell snippet:
#!/bin/sh
if tput setaf >/dev/null 2>&1; then tput_init_linux else tput_init_none;
elif tput AF >/dev/null 2>&1; then tput_init_bsd else tput_init_none;
else tput_init_none; fi
ShellCheck 0.10.0 does say nothing about it, I found it basically by accident.
I tested as follows:
1)
if tput setaf >/dev/null 2>&1; then tput_init_linux else tput_init_none; fi
this went ok: tput_init_linux: command not found
2) Reverting the logic with !
:
if ! tput setaf >/dev/null 2>&1; then tput_init_linux else tput_init_none; fi
**says nothing**, but if I add one semicolon:
3)
if ! tput setaf >/dev/null 2>&1; then tput_init_linux; else tput_init_none; fi
it appears to work as expected: tput_init_none: command not found
***
But I seem to be unable to chain these multiple if
-statements afterward.
***
So as you can see, I reached a state, where one statement works, but chaining it seems _problematic_. Can anyone help?
Vlastimil Burián
(30505 rep)
May 23, 2024, 07:08 AM
• Last activity: May 24, 2024, 10:38 AM
2
votes
1
answers
111
views
Shell detection of empty subshell
[SC1143](https://www.shellcheck.net/wiki/SC1143) suggests that commented parts of a wrapped shell command to be wrapped in a subshell. Is the Posix shell "smart enough" to not launch a subshell when it sees that it does nothing? What about Bash and Zsh?
[SC1143](https://www.shellcheck.net/wiki/SC1143) suggests that commented parts of a wrapped shell command to be wrapped in a subshell.
Is the Posix shell "smart enough" to not launch a subshell when it sees that it does nothing? What about Bash and Zsh?
AvidSeeker
(43 rep)
Mar 14, 2024, 01:41 AM
• Last activity: Mar 15, 2024, 11:26 AM
4
votes
2
answers
702
views
Why must I not quote a string variable when running it as a command?
My Ubuntu/Debian-based Linux update POSIX shell script seems to require that I **not double quote** the string variable with the stored command, which is being executed. As I don't understand this issue, I'd like to ask why that is? And if the code is correct as it is? Warning: SC2086, [wiki][1], "D...
My Ubuntu/Debian-based Linux update POSIX shell script seems to require that I **not double quote** the string variable with the stored command, which is being executed. As I don't understand this issue, I'd like to ask why that is? And if the code is correct as it is?
Warning: SC2086, wiki , "Double quote to prevent globbing and word splitting."
The script follows, the problematic part is highlighted:
#!/bin/sh
# exit script when it tries to use undeclared variables
set -u
# color definitions
readonly red=$(tput bold)$(tput setaf 1)
readonly green=$(tput bold)$(tput setaf 2)
readonly yellow=$(tput bold)$(tput setaf 3)
readonly white=$(tput bold)$(tput setaf 7)
readonly color_reset=$(tput sgr0)
# to create blocks of texts, I separate them with this line
readonly block_separator='----------------------------------------'
step_number=0
execute_jobs ()
{
while [ ${#} -gt 1 ]
do
job_description=${1}
job_command=${2}
step_number=$(( step_number + 1 ))
printf '%s\n' "Step #${step_number}: ${green}${job_description}${color_reset}"
printf '%s\n' "Command: ${yellow}${job_command}${color_reset}"
printf '%s\n' "${white}${block_separator}${color_reset}"
# RUN THE ACTUAL COMMAND
# ShellCheck warns me I should double quote the parameter
# If I did, it would become a string (I think) and I'd get 'command not found' (proven)
# As I don't understand the issue, I left it as I wrote it, without quotes
### shellcheck disable=SC2086
if sudo ${job_command} #
then
printf '\n'
else
printf '%s\n\n' "${red}An error occurred.${color_reset}"
exit 1
fi
shift 2
done
}
execute_jobs \
'configure packages' 'dpkg --configure --pending' \
'fix broken dependencies' 'apt-get --assume-yes --fix-broken install' \
'update cache' 'apt-get update' \
'upgrade packages' 'apt-get --assume-yes upgrade' \
'upgrade packages with possible removals' 'apt-get --assume-yes dist-upgrade' \
'remove unused packages' 'apt-get --assume-yes --purge autoremove' \
'clean up old packages' 'apt-get autoclean'
Vlastimil Burián
(30505 rep)
May 10, 2019, 08:54 AM
• Last activity: Nov 10, 2022, 08:28 AM
1
votes
1
answers
205
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 multipass list --format json | jq -r '.list[] | [ .name, .ipv4[0] ] | @tsv' | while IFS=$'\t' read -r name ip...
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
multipass list --format json | jq -r '.list[] | [ .name, .ipv4 ] | @tsv' |
while IFS=$'\t' read -r name ipaddress; do
# shellcheck disable=SC2030
LOCAL_NAMES+=("$name")
# shellcheck disable=SC2030
LOCAL_HOSTS+=($ipaddress)
done
# shellcheck disable=SC2031
reply=("${LOCAL_NAMES[@]}" "${LOCAL_HOSTS[@]}")
echo "${reply[@]}"
}
declare as declare -gx
gives the same warning?
Chris G.
(163 rep)
Jul 29, 2022, 09:58 AM
• Last activity: Jul 29, 2022, 12:16 PM
1
votes
1
answers
151
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.com/questions/29832037/how-to-get-script-directory-in-posix-sh ``` dir=$(CDPATH= cd -- "$(dirname -- "$...
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.com/questions/29832037/how-to-get-script-directory-in-posix-sh
dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
^-- SC1007: Remove space after = if trying to assign a value (for empty string, use var='' ... ).
Removing CDPATH=
results in ShellCheck passing, and it still seems to work, but...
> The CDPATH= prefix takes the place of > /dev/null in the original command: $CDPATH is set to a null string so as to ensure that cd never echoes anything.
Looks like it's needed. So, is there any way to make this pass ShellCheck? Or just ignore it?
rannday
(11 rep)
Jun 16, 2022, 12:57 PM
• Last activity: Jun 16, 2022, 01:07 PM
7
votes
4
answers
2497
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: ```bash AREA_ARG="" if __SOME_SETTING__ ; then AREA_ARG=" --area us,ca " fi process_data -i /some/path $AREA_ARG ``` i.e. bash either executes `process_data -i /some/pa...
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=" --area us,ca "
fi
process_data -i /some/path $AREA_ARG
i.e. bash either executes process_data -i /some/path
, or process_data -i /some/path --area us,ca
.
However [shellcheck
](https://www.shellcheck.net/) complains!
$ shellcheck test.sh
In test.sh line 7:
process_data -i /some/path $AREA_ARG
^-------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
process_data -i /some/path "$AREA_ARG"
For more information:
https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
I understand the principle, but I _want_/_need_ the variable to split on the space so that process_data
gets 2 arguments.
What's the Proper Way™ to do this in bash
?
Amandasaurus
(1336 rep)
May 18, 2022, 09:15 AM
• Last activity: May 19, 2022, 04:16 PM
6
votes
1
answers
2764
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`**: shellcheck my_script I get notification like this one: . ./functions/my_function ^-- SC1091: No...
### 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
**:
shellcheck my_script
I get notification like this one:
. ./functions/my_function
^-- SC1091: Not following: ... was not specified as input (see shellcheck -x).
SC1091 on GitHub
***
### My ShellCheck
I'm working with self-compiled ShellCheck located in:
~/.cabal/bin/shellcheck
***
### Goal
I'm working with Visual Studio Code GUI text editor. Is there a way to force the -x
switch in there somewhere or other solution?
Vlastimil Burián
(30505 rep)
Aug 9, 2019, 09:25 AM
• Last activity: Feb 9, 2022, 11:46 PM
6
votes
1
answers
7328
views
if ! <command> (...) vs. <command> ; if [ $? -eq 0 ] (...)
I am working on a shell script and decided to check my work via [shellcheck.net][1]. I am able to get functionally the same behavior of the following two lines in my script: findmnt /dev/sda1 >/dev/null ; if [ $? -eq 0 ]; then echo 1; else echo 0; fi vs. if ! findmnt /dev/sda1 >/dev/null; then echo...
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 ; if [ $? -eq 0 ]; then echo 1; else echo 0; fi
vs.
if ! findmnt /dev/sda1 >/dev/null; then echo 0; else echo 1; fi
However shellcheck throws :
> SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly
> with $?.
It is not immediately clear to me which to use. I do see: https://github.com/koalaman/shellcheck/issues/1167 which seems to have amended this for several possible values. I want to be sure that I am writing something that uses best practices and will run without issue and report accurately.
Kahn
(1827 rep)
Sep 28, 2021, 06:45 PM
• Last activity: Sep 28, 2021, 07:47 PM
4
votes
1
answers
3518
views
how to get user input with a prompt into a variable in a posix compliant way
```sh 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 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 compliant way?
testoflow
(137 rep)
May 20, 2021, 08:31 PM
• Last activity: May 20, 2021, 10:59 PM
-2
votes
1
answers
108
views
ShellCheck warning of individual redirects
I am using here document to create a startup script, when I checked my code on it gives me a warning which it can be ignored. But I am wondering if there is a better way to write a code and avoid that warning if possible. ``` cat > /usr/local/etc/rc.d/"${name}" #!/bin/sh . /etc/rc.subr cpu="${cpu}"...
I am using here document to create a startup script, when I checked my code on it gives me a warning which it can be ignored. But I am wondering if there is a better way to write a code and avoid that warning if possible.
cat > /usr/local/etc/rc.d/"${name}"
#!/bin/sh
. /etc/rc.subr
cpu="${cpu}"
ram="${ram}"
tap="${tap}"
name="${name}"
EOF
sed -n '3,16p' ./bhyve >> /usr/local/etc/rc.d/"${name}"
cat > /usr/local/etc/rc.d/"${name}"
start_cmd=${name}_start
stop_cmd=${name}_stop
restart_cmd=${name}_restart
delete_cmd=${name}_delete
${name}_start() {
EOF
cat > /usr/local/etc/rc.d/"${name}"
while true; do
bhyve -Hw -c "${cpu}" -m "${ram}"G \
-s 0,hostbridge \
-s 1,virtio-net,"${tap}" \
-s 2,virtio-blk,/dev/zvol/zroot/VMs/"${name}"/disk0 \
-s 29,fbuf,tcp=0.0.0.0:"${vnc}",w=1024,h=768 \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/zroot/VMs/efi.fd \
"${name}" || break;
done > /dev/null 2>&1 &
}
EOF
cat > /usr/local/etc/rc.d/"${name}"
${name}_stop() {
EOF
cat > /usr/local/etc/rc.d/"${name}"
bhyvectl --vm="${name}" --force-poweroff
}
EOF
cat > /usr/local/etc/rc.d/"${name}"
${name}_restart() {
EOF
cat > /usr/local/etc/rc.d/"${name}"
bhyvectl --vm="${name}" --force-reset
}
EOF
cat > /usr/local/etc/rc.d/"${name}"
${name}_delete() {
EOF
cat > /usr/local/etc/rc.d/"${name}"
bhyvectl --vm="${name}" --destroy
sleep 5
ifconfig "${tap}" destroy
sysrc cloned_interfaces-="${tap}"
EOF
cat > /usr/local/etc/rc.d/"${name}"
sed -i '' 's/ addm ${tap}//g' /etc/rc.conf
sed -i '' 's/service ${name} start || sleep 5//g' /usr/local/etc/rc.d/bhyve
sed -i '' '/^$/d' /usr/local/etc/rc.d/bhyve
EOF
cat > /usr/local/etc/rc.d/"${name}"
zfs destroy -r zroot/VMs/"${name}"
rm /usr/local/etc/rc.d/"${name}"
}
load_rc_config "${name}"
run_rc_command "$1"
EOF
# Add the VM to /usr/local/etc/rc.d/bhyve for autostart
sed -i '' -e "9s/^/service ${name} start || sleep 5\n/g" /usr/local/etc/rc.d/bhyve
Amr
(61 rep)
Dec 27, 2020, 11:45 PM
• Last activity: Dec 28, 2020, 01:18 PM
4
votes
2
answers
988
views
ShellCheck warning regarding quoting ("A"B"C")
I am writing simple shell script and when I check my script at it give me error at line 14 Line 14: sysrc ifconfig_"${Bridge}"="addm ${NIC}" ^-- SC2140: Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"? In fact I didn't understand how to correct it ``` #!/bin/sh Setup() { #...
I am writing simple shell script and when I check my script at it give me error at line 14
Line 14:
sysrc ifconfig_"${Bridge}"="addm ${NIC}"
^-- SC2140: Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"?
In fact I didn't understand how to correct it
#!/bin/sh
Setup() {
# Determine interface automatically
NIC="$(ifconfig -l | awk '{print $1}')"
# Enabling the Bridge
Bridge="$(ifconfig bridge create)"
# Next, add the local interface as member of the bridge.
# for the bridge to forward packets,
# all member interfaces and the bridge need to be up:
ifconfig "${Bridge}" addm "${NIC}" up
# /etc/rc.conf
sysrc cloned_interfaces="${Bridge}"
sysrc ifconfig_"${Bridge}"="addm ${NIC}"
# Create bhyve startup script
touch /usr/local/etc/rc.d/bhyve
chmod +x /usr/local/etc/rc.d/bhyve
cat > /usr/local/etc/rc.d/bhyve
#!/bin/sh
# PROVIDE: bhyve
# REQUIRE: DAEMON
# KEYWORD: shutdown
. /etc/rc.subr
name=bhyve
start_cmd="${name}"_start
bhyve_start() {
}
load_rc_config "${name}"
run_rc_command "$1"
EOF
sysrc bhyve_enable="YES"
}
Amr
(61 rep)
Dec 26, 2020, 10:46 PM
• Last activity: Dec 27, 2020, 05:09 PM
1
votes
4
answers
2556
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 over ls output is fragile. Use globs.
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 over ls output is fragile. Use globs.
nath
(6094 rep)
Jan 5, 2020, 03:04 AM
• Last activity: Nov 9, 2020, 06:07 PM
-3
votes
2
answers
166
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 # shellcheck disable=SC2034 DISTRO_VERSION=$VERSION_ID fi } # Check Operating System dist-check # Pre-Checks function instal...
# Detect Operating System
function dist-check() {
# shellcheck disable=SC1090
if [ -e /etc/os-release ]; then
# shellcheck disable=SC1091
source /etc/os-release
DISTRO=$ID
# shellcheck disable=SC2034
DISTRO_VERSION=$VERSION_ID
fi
}
# Check Operating System
dist-check
# Pre-Checks
function installing-system-requirements() {
# shellcheck disable=SC2233,SC2050
if ([ "$DISTRO" == "ubuntu" ] || [ "$DISTRO" == "debian" ] || [ "DISTRO" == "raspbian" ]); then
apt-get update && apt-get install iptables curl coreutils bc jq sed e2fsprogs -y
fi
# shellcheck disable=SC2233,SC2050
if ([ "$DISTRO" == "fedora" ] || [ "$DISTRO" == "centos" ] || [ "DISTRO" == "rhel" ]); then
yum update -y && yum install epel-release iptables curl coreutils bc jq sed e2fsprogs -y
fi
if [ "$DISTRO" == "arch" ]; then
pacman -Syu --noconfirm iptables curl bc jq sed
fi
}
# Run the function and check for requirements
installing-system-requirements
Why wont this run?
I am using ||
to separate the distros but its still not working.
Prajwal Koirala
(15 rep)
Oct 31, 2020, 01:52 AM
• Last activity: Oct 31, 2020, 08:12 AM
4
votes
3
answers
2093
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 Double quote to prevent globbing and word splitting. I'm not worried about word splitting in this case, but in a lot of other cases I am, so I'm trying to keep...
While tracking down an error in my shellscript, I found the following behavior in this code snippet:
declare -a filelist
readarray filelist Double quote to prevent globbing and word splitting.
I'm not worried about word splitting in this case, but in a lot of other cases I am, so I'm trying to keep my code consistent. However, when I double quote the array, the command fails. Simplifying the code to a single element gives the following:
bash-5.0# sha256sum ${filelist} | head -c 64
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
bash-5.0# sha256sum "${filelist}" | head -c 64
sha256sum: can't open 'file1
': No such file or directory
I can obviously just... not double quote because in this instance word splitting isn't a concern. But I wanted to post because in the future it might be.
My question has two parts:
1. Is there a "best-practices" way to prevent word splitting other than double quoting the array as above?
2. Where are the single quotes coming from in the array? Edit: there are no single quotes. The single quotes are the error showing the name of the file that cannot be opened.
Also, just out of curiosity, why does
echo ${filelist}
not contain an additional newline but echo "${filelist}"
does?
dcwaters
(461 rep)
Apr 23, 2020, 03:53 PM
• Last activity: Apr 24, 2020, 07:07 AM
5
votes
1
answers
17439
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 "${servers[@])" do for job in "${jobbs[@]}" do for race in "${races[@]}" do for range in "${ranges[@]}" do cd ${RESU...
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 "${servers[@])"
do
for job in "${jobbs[@]}"
do
for race in "${races[@]}"
do
for range in "${ranges[@]}"
do
cd ${RESULTS}
cd "$server"
cd "$job"
cd "$race"
cd "$range"
for CHR in {1..22}
do
mv -v "$CHR".vcf.gz chr"$CHR".dose.vcf.gz
mv -v "$CHR".vcf.gz.csi chr"$CHR".dose.vcf.gz.csi
done # chromo
done # range
done # race
done # job
done # server
My Bash terminal returns the errors:
./rename.sh: line 41: unexpected EOF while looking for matching `"'
./rename.sh: line 52: syntax error: unexpected end of file
ShellCheck output is below:
Line 9:
for server in "${servers[@])"
^-- SC1009: The mentioned syntax error was in this parameter expansion.
Line 32:
mv -v "$CHR".vcf.gz chr"$CHR".dose.vcf.gz
^-- SC1078: Did you forget to close this double quoted string?
Line 33:
mv -v "$CHR".vcf.gz.csi chr"$CHR".dose.vcf.gz.csi
^-- SC1079: This is actually an end quote, but due to next char it looks suspect.
^-- SC1073: Couldn't parse this double quoted string. Fix to allow more checks.
Line 43:
done # server
^-- SC1072: Expected end of double quoted string. Fix any mentioned problems and try again.
Could any please help and check if I've missed something? Thanks!
Jared
(53 rep)
Apr 9, 2020, 08:14 AM
• Last activity: Apr 9, 2020, 08:15 AM
9
votes
2
answers
1545
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 in $(${aws} ec2 describe-instances --query 'Reservations[].Instances[][].{Name: Tags[?Key==`Name...
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 in $(${aws} ec2 describe-instances --query 'Reservations[].Instances[][].{Name: Tags[?Key==Name
].Value[] | }' --filters "Name=tag:Name,Values=${server_name}*" --output text);
^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.
I can't get the code to line up correctly in the SO editor but the ^--
is pointing at the *
in the code. This part:
"Name=tag:Name,Values=${server_name}*"
The error provides a link to ShellCheck documentation for reference but when I double check everything, it looks like I'm in compliance. :D
I am guessing that the *
is throwing things off and I know that I can get around this by doing shellcheck -e SC2016
but I'm really wondering what might be causing shellcheck to carp.
Any ideas?
Michael J
(583 rep)
Mar 18, 2020, 08:22 PM
• Last activity: Mar 19, 2020, 01:03 PM
0
votes
0
answers
89
views
Why does running shellcheck from the demo flatpak work, but fail in Atom?
I've installed [Atom from flathub](https://flathub.org/apps/details/io.atom.Atom). Now using the [linter-shellcheck](https://github.com/AtomLinter/linter-shellcheck) fails and says, the shellcheck command is not available. However, if I [use the flatpak demo application](https://flathub.org/apps/det...
I've installed [Atom from flathub](https://flathub.org/apps/details/io.atom.Atom) . Now using the [linter-shellcheck](https://github.com/AtomLinter/linter-shellcheck) fails and says, the shellcheck command is not available.
However, if I [use the flatpak demo application](https://flathub.org/apps/details/org.flatpak.qtdemo) and use [
flatpak enter
](https://unix.stackexchange.com/questions/500225/how-to-get-flatpak-enter-to-work/504144) to execute a shell inside of it, I can actually run shellcheck
without any issues.
Howwever, the demo applications has much less permissions than the Atom's flatpak.
So how is this possible? Or, where is the error here?
[MY question here would be obsolete](https://unix.stackexchange.com/questions/412869/how-to-allow-gui-application-in-flatpak-to-run-cli-tool/422438) if it just orked to run shellcheck
in the flatpak.
**Edit:**
_Inside_ of the flatpak, here is where shellcheck and so on are:
$ which shellcheck
/usr/bin/shellcheck
$ echo $PATH
/usr/share/Modules/bin:/app/bin:/usr/bin
(This is the demo flatpak, i.e. where I can execute it successfully.)
rugk
(3496 rep)
Mar 19, 2019, 05:34 PM
• Last activity: Mar 19, 2019, 06:17 PM
17
votes
1
answers
7773
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 }') What does "masking return values" mean, and how does it pertain to the aforementioned warning?
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 }')
What does "masking return values" mean, and how does it pertain to the aforementioned warning?
user332459
Mar 14, 2019, 08:30 PM
• Last activity: Mar 14, 2019, 09:18 PM
Showing page 1 of 20 total questions