Open hehaoqian opened 1 year ago
My first question is how much do we care about posix mode but then I saw
bash is invoked with "sh", such as invoking /bin/sh in CentOS7, which symlinks /bin/sh to /bin/bash
I'm fine with someone going in and fixing this with a reasonable level of care taken to avoid name conflicts.
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 bothhello-world
andhello_world
Maybe a more complex escape is needed for robustness. Also, additional escape needed to satisfythey 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