Generated bash completion script not work in POSIX mode #5011
Labels
A-completion
Area: completion generator
C-bug
Category: Updating dependencies
E-medium
Call for participation: Experience needed to fix: Medium / intermediate
Please complete the following tasks
Rust Version
1.70.0
Clap Version
4.3.11
Minimal reproducible code
Steps to reproduce the bug with the above code
Actual Behaviour
The shell errors with the following message, with non-zero return code
./hello-world.bash: line 36: `_hello-world': not a valid identifier
Expected Behaviour
The script should work in bash posix mode.
I want to emphasize that this issue report,
does NOT request to make the script work in non-bash, POSIX only "sh" shell,
such as
/bin/sh
in ubuntu.Only requesting to make the script work in POSIX mode of
/bin/bash
Bash doc https://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html says
In my example, the function name of generated script is
_hello-world
, which is invalid in POSIX modeThis should be simple to fix, if dash character is properly escaped
The simplest way would be replacing
-
by_
,but it would cause conflict if generating completion script for both
hello-world
andhello_world
Maybe a more complex escape is needed for robustness.
Also, additional escape needed to satisfy
they may not contain characters other than letters, digits, and underscores, and may not start with a digit
requirementAdditional Context
There are several ways to enter bash in posix mode:
--enable-strict-posix-default
, then posix mode is the default/bin/sh
in CentOS7, which symlinks/bin/sh
to/bin/bash
Debug Output
No response
The text was updated successfully, but these errors were encountered: