Skip to content

complete -p commands do not work with source-sh #646

Closed

Description

@acouture

Describe the bug

complete or complete -p commands print nothing when they are in a file that is sourced with source-sh bash <file> or with module sh-to-mod bash <file>.

To Reproduce

Steps to reproduce the behavior:

$ complete -p bash
complete -F _longopt bash
$ module show test/complete
-------------------------------------------------------------------
/path/to/modulefiles/test/complete:

setenv          COMPLETE_OUTPUT {}
-------------------------------------------------------------------
$ module load test/complete
$ env | grep COMPLETE_OUTPUT
COMPLETE_OUTPUT=
__MODULES_LMSOURCESH=test/complete&bash ~/complete.sh|setenv COMPLETE_OUTPUT {}

Location and content of any modulerc or modulefile involved:

$ cat /path/to/modulefiles/test/complete
#%Module

source-sh bash ~/complete.sh
$ cat ~/complete.sh
#!/bin/bash

export COMPLETE_OUTPUT=$(complete -p bash)

Expected behavior

After module load test/complete, the variable COMPLETE_OUTPUT must be set to complete -F _longopt bash.

Error and debugging information

$ module --debug load test/complete
[...]
DEBUG [#1:load:test/complete] evaluateModulefile: getModuleContent /path/to/modulefiles/test/complete
DEBUG [#1:load:test/complete] evaluateModulefile: source-sh bash ~/complete.sh
DEBUG [#1:load:test/complete] execShAndGetEnv: running '/usr/bin/bash --noprofile --norc -c {export -p; echo %ModulesShToMod%; declare -f; echo %ModulesShToMod%; alias; echo %ModulesShToMod%; complete; echo %ModulesShToMod%; pwd; echo %ModulesShToMod%; . ~/complete.sh 2>&1; echo %ModulesShToMod%; export -p; echo %ModulesShToMod%; declare -f; echo %ModulesShToMod%; alias; echo %ModulesShToMod%; complete; echo %ModulesShToMod%; pwd}'
DEBUG [#1:load:test/complete] execShAndGetEnv: script output is '/path/to/complete.sh: line 3: complete: bash: no completion specification'
DEBUG [#1:load:test/complete] sh-to-mod: resulting env changes '{setenv COMPLETE_OUTPUT {}}'
DEBUG [#1:load:test/complete] source-sh: setenv COMPLETE_OUTPUT {}
DEBUG [#1:load:test/complete] parseSetenvCommandArgs: bhv=set, var=COMPLETE_OUTPUT, val=
DEBUG [#1:load:test/complete] unset-env: __MODULES_SHARE_COMPLETE_OUTPUT (internal=1, val=)
DEBUG [#1:load:test/complete] unset-env: __MODULES_PUSHENV_COMPLETE_OUTPUT (internal=1, val=)
DEBUG [#1:load:test/complete] set-env: COMPLETE_OUTPUT=
DEBUG [#1:load:test/complete] interp-sync-env: set var='::env(COMPLETE_OUTPUT)', val='' on interp(s) __modfile_load_1_1
DEBUG [#1:load:test/complete] evaluateModulefile: module-info mode
DEBUG [#1:load:test/complete] getModuleLoadedConflict: 'test/complete' conflicts with ''
DEBUG [#1:load:test/complete] execute-modulefile: exiting /path/to/modulefiles/test/complete
[...]

Modules version and configuration

$ module --version
Modules Release 5.6.0 (2025-07-31)
$ module config --dump-state

Additional context

It looks like the new instance of bash reset the whole environment. I can reproduce this outside of module with :

$ bash -c 'complete -p bash'
bash: line 0: complete: bash: no completion specification

I can get it to work with :

$ bash -i -c 'complete -p bash'
complete -F _longopt bash

However I only have the default environment initialized with bash. I loose any additional complete commands :

$ complete foo
$ complete -p foo
complete foo
$ bash -i -c 'complete -p foo'
bash: complete: foo: no completion specification

Activity

  1. xdelaruelle commented on Jul 13, 2026

    @xdelaruelle
    Collaborator

    Many thanks @acouture for this report.

    The issue you face is due to the kind of shell execution run, which is non-interactive and without any shell profile loaded. In such conditions, volatile elements like shell alias, functions or completions are not initialized. So you cannot expect to get the shell alias, functions and completions you get in your interactive shell within the execution of your source-sh shell script.

    I will update the documentation of source-sh and sh-to-mod to highlight this point.

  2. added this to the 5.7.0 milestone on Jul 14, 2026
  3. added a commit that references this issue on Jul 15, 2026
    898e471
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions