Skip to content

Commit 03065cd

Browse files
mcdonnnjCopilot
andcommitted
Adjust GNU getopt check logic in the setup-env script
Change the check from looking for specific text in the version output to using the `--test` option. This will provide a more robust implementation of this check that does not have to worry about output format stability. Co-authored-by: Copilot <[email protected]>
1 parent d2d8236 commit 03065cd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

setup-env

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ LONGOPTS="force,help,install-hooks,list-versions,python-version:,venv-name:"
101101
# Define short options for getopt
102102
SHORTOPTS="fhilp:v:"
103103

104-
# Check for GNU getopt by matching a specific pattern ("getopt from util-linux")
105-
# in its version output. This approach presumes the output format remains stable.
106-
# Be aware that format changes could invalidate this check.
107-
if [[ $(getopt --version 2> /dev/null) != *"getopt from util-linux"* ]]; then
104+
# Check for GNU getopt by testing for long option support. GNU getopt supports
105+
# the "--test" option and will return exit code 4 while POSIX/BSD getopt does
106+
# not and will return exit code 0.
107+
if getopt --test > /dev/null 2>&1; then
108108
cat << 'END_OF_LINE'
109109
110110
Please note, this script requires GNU getopt due to its enhanced

0 commit comments

Comments
 (0)