Shellsheck is a static analysis tool for shell scripts which can be installed local on some Linux systems and can used without installation online for checking bash scripts for some errors.
Testing envirement:
main.sh
#!/bin/bash
source ./sourcefile.sh
echo "Output from main.sh"
echo
echo
fkt_output_from_sourcefile_sh
echo
echo
echo "For closing window, press Enter or Ctl + C"; read -r
sourcefile.sh
#!/bin/bash
fkt_output_from_sourcefile_sh() {
echo "Output from sourcefile.sh"
}
How did I run it on terminal:
shellcheck -x main.sh
Output on terminal (looks working fine):
Output from main.sh
Output from sourcefile.sh
For closing window, press Enter or Ctl + C
Error Message by check by shellcheck -x:
In /home/user/desktop/main.sh line 8:
source ./sourcefile.sh
^-- SC1091: Not following: ./sourcefile.sh: openBinaryFile: does not exist (No such file or directory)
Possible solution (which did not work for me, probably depend on my wrong syntax):
Sample of not working solution:
Based on: "Tell ShellCheck where to find a sourced file (since 0.4.0):"
# shellcheck source=src/examples/config.sh
. "$(locate_config)"
Source:
main.sh
#!/bin/bash
# shellcheck source=./sourcefile.sh
source "$(find_install_dir)/sourcefile.sh"
echo "Output from main.sh"
echo
echo
fkt_output_from_sourcefile_sh
echo
echo
echo "For closing window, press Enter or Ctl + C"; read -r
sourcefile.sh :
#!/bin/bash
fkt_output_from_sourcefile_sh() {
echo "Output from sourcefile.sh"
}
Error message on terminal:
/home/user/desktop/main.sh: Line 4: find_install_dir: Command not found.
/home/user/desktop/main.sh: Line 4: /sourcefile.sh: File or folder not found
Output from main.sh
/home/user/desktop/main.sh: Line 10: fkt_output_from_sourcefile_sh: Command not found.
For closing window, press Enter or Ctl + C
I reviewed your situation better, and found this issue on shellcheck
's github:
https://github.com/koalaman/shellcheck/issues/1356 (This specific comment)
From what I understood, there are 2 solutions mentioned from developers:
1. Solving SC1091:
Because this error wasn't shown to me again with your edited code as well, and I don't see your shellcheck
comment about SC1091
above source ./sourcefile.sh
, I only can suggest you to add this comment in main.sh
, and check again:
...
# shellcheck disable=SC1091
source ./sourcefile.sh
...
Then run:
$ shellcheck main.sh
2. Read this if shellcheck
was installed using snap
:
snap will block access to any other directories that are not in /home
//media
but looking into your logs it seems like your scripts are in /home/user
so that's not a problem, it may be #1.