shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

bash coproc

Open megaannum opened this issue 1 year ago • 7 comments

ShellCheck version 0.10.0 uname -a Linux olympia 6.11.11-300.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 18:38:25 UTC 2024 x86_64 GNU/Linux

When I enter this on the shellcheck website I get no errors:

#!/bin/bash
  
if [[ ! -v $LOAD_ONCE ]]; then
  declare -r LOAD_ONCE=1

  function do_coproc() {
    # shellcheck disable=SC2034
    local -r fn="$1"
    # shellcheck disable=SC2034
    local -ra args=( "${@:2}" )

    # shellcheck disable=SC2034
    local NAME="CP_${FUNCNAME[1]}"
    # shellcheck disable=SC1083
    coproc $NAME { LOG.redefine_jmps_child; $fn "${args[@]}"; }
    # eval 'coproc $NAME { LOG.redefine_jmps_child; $fn "${args[@]}"; }'
  }

fi

but when it is a file Test.sh and I run: shellcheck Test.sh I get:

$ shellcheck  Test.sh

In Test.sh line 3:
if [[ ! -v $LOAD_ONCE ]]; then
^-- SC1046 (error): Couldn't find 'fi' for this 'if'.
^-- SC1073 (error): Couldn't parse this if expression. Fix to allow more checks.


In Test.sh line 17:
  }
  ^-- SC1047 (error): Expected 'fi' matching previously mentioned 'if'.
   ^-- SC1072 (error): Unexpected keyword/token. Fix any mentioned problems and try again.

For more information:
  https://www.shellcheck.net/wiki/SC1046 -- Couldn't find 'fi' for this 'if'.
  https://www.shellcheck.net/wiki/SC1047 -- Expected 'fi' matching previously...
  https://www.shellcheck.net/wiki/SC1072 -- Unexpected keyword/token. Fix any..

Does the website use a later version? If so, how can I get it? Using the "eval" line instead works but I would prefer a fixed version. Thanks

megaannum avatar Jan 18 '25 21:01 megaannum

SC1089: Also, with regard to SC1089 ShellCheck version 0.10.0 $uname -a Linux olympia 6.11.11-300.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 18:38:25 UTC 2024 x86_64 GNU/Linux $ bash --version GNU bash, version 5.2.32(1)-release (x86_64-redhat-linux-gnu)

If I paste the code from SC1089: #!/usr/bin/env bash coproc COPROC_NAME1 { echo "/directory" ; } echo "${COPROC_NAME1[0]}" coproc "COPROC_NAME2" { echo "/directory" ; } cname="COPROC_NAME_$$" coproc "$cname" { echo "/directory" ; }

into the file X.sh and run shellcheck I get: $ shellcheck X.sh

In X.sh line 4: coproc "COPROC_NAME2" { echo "/directory" ; } ^-- SC1083 (warning): This { is literal. Check expression (missing ;/\n?) or quote it. ^-- SC1089 (error): Parsing stopped here. Is this keyword correctly matched up?

For more information: https://www.shellcheck.net/wiki/SC1083 -- This { is literal. Check expressi... https://www.shellcheck.net/wiki/SC1089 -- Parsing stopped here. Is this key...

So, SC1089 does not seem to be fixed.

megaannum avatar Jan 19 '25 16:01 megaannum

previous comment add: SC1089: bash: coproc "NAME" { ...; } - quoted NAME kills parsing #3048

megaannum avatar Jan 19 '25 16:01 megaannum

Does the website use a later version? If so, how can I get it?

yes. the web uses the latest git HEAD, there are build instructions in the README.

brother avatar Jan 20 '25 07:01 brother

Thanks. Just finished compiling/testing and it works. BTW, you might add to the README build instructions that ghc also has to be installed. Richard

On 19/01/25 23:53, brother wrote:

Does the website use a later version? If so, how can I get it?

yes. the web uses the latest git HEAD, there are build instructions in the README.

— Reply to this email directly, view it on GitHub https://github.com/koalaman/shellcheck/issues/3126#issuecomment-2601663897, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMYHFKZ6JCR4C7U5KFOIVD2LSTQRAVCNFSM6AAAAABVN7HD6WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMBRGY3DGOBZG4. You are receiving this because you authored the thread.Message ID: @.***>

megaannum avatar Jan 20 '25 14:01 megaannum

Thanks. Just finished compiling/testing and it works. BTW, you might add to the README build instructions that ghc also has to be installed.

What system did not have it as a hard dependency? The documentation for cabal-install is pretty clear that ghc will be needed. A PR with a better language is welcome as always, not sure it really is needed myself.

brother avatar Jan 20 '25 14:01 brother

Maybe two decades ago or more I played around writing a couple of very small Haskell programs. Don't know if I had heard of Cabal at that time. So, for someone not familiar with the Haskell ecosystem (e.g., not having read the cabal-install documentation) knowing that ghc is required only becomes know when one executed cabal-install and it tells you that you need it.

On 20/01/25 06:35, brother wrote:

Thanks. Just finished compiling/testing and it works.
BTW, you might add to the README build instructions that ghc also has to be installed.

What system did not have it as a hard dependency? The documentation for cabal-install is pretty clear that ghc will be needed. A PR with a better language is welcome as always, not sure it really is needed myself.

— Reply to this email directly, view it on GitHub https://github.com/koalaman/shellcheck/issues/3126#issuecomment-2602584969, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMYHFK5ZXAMNYAZIU5X3OT2LUCT7AVCNFSM6AAAAABVN7HD6WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMBSGU4DIOJWHE. You are receiving this because you authored the thread.Message ID: @.***>

megaannum avatar Jan 20 '25 14:01 megaannum

And it's in the very first line of the quick start guide of cabal-install.

Start by installing the cabal executable (see the previous section) and the Haskell compiler ghc.

brother avatar Jan 20 '25 14:01 brother