Skip to content

Brackets should be escaped on Csh shells #565

Closed

Description

@xdelaruelle

When defining an alias containing bracket characters ([]), if module is run against csh/tcsh shells, an error is obtained.

Example modulefile:

#%Module
set osrel 80
set-alias mycommand "bsub -R \"select[type==X64LIN && osrel==$osrel]\" myapp"

Error when running module:

$ module load ./test
alias: No match.

It seems bracket characters have a special meaning on Csh shell. Thus they should be escaped when module produces shell output.

Activity

  1. Laurent-Besson commented on Jan 30, 2025

    @Laurent-Besson
    Contributor

    On the mailing list, I proposed the following workaround:

    proc charEscaped {str {charlist " \\\t{}[]|<>!;#^$&*?"'`()"}} {
    return [regsub -all "([$charlist])" $str {\\1}]
    }

    proc charUnescaped {str {charlist " \\\t{}[]|<>!;#^$&*?"'`()"}} {
    return [regsub -all "\\([$charlist])" $str {\1}]
    }

    where I have added "[]" in the list of char to escape. Though it solves the issue for the "set-alias", it breaks the definition of __MODULES_LMCONFLICT variable. During an "unload" command, I get some "&" (instead of ":") as separator during the different modules. This is causing severe error under tcsh

  2. Laurent-Besson commented on Jan 30, 2025

    @Laurent-Besson
    Contributor

    Seems GitHub interface has removed some backslashes from my previous comment. To be clear, initial workaround was:

    proc charEscaped {str {charlist " \\\\\t{}\[\]|<>!;#^\$&*?\"'`()"}} {
       return [regsub -all "\(\[$charlist\]\)" $str {\\\1}]
    }
    
    proc charUnescaped {str {charlist " \\\\\t{}\[\]|<>!;#^\$&*?\"'`()"}} {
       return [regsub -all "\\\\\(\[$charlist\]\)" $str {\1}]
    }
  3. added a commit that references this issue on Jan 31, 2025
    46fcc17
  4. xdelaruelle commented on Jan 31, 2025

    @xdelaruelle
    CollaboratorAuthor

    Additional backslashes should be added to escape the brackets on the regsub command. On my way to fix this.

  5. added this to the 5.6.0 milestone on Jan 31, 2025
  6. xdelaruelle commented on Jan 31, 2025

    @xdelaruelle
    CollaboratorAuthor

    As a workaround, the puts command can be used as you control with it the shell code that is produced:

    #%Module
    set osrel 80
    puts stdout "alias mycommand bsub\\ -R\\ \"select\\\[type==X64LIN && osrel==$osrel\\\]\"\\ myapp;"
  7. added a commit that references this issue on Feb 2, 2025
    f31d010
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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions