refactor: simplify sed/awk/grep uses, etc.#1574
Open
akinomyoga wants to merge 6 commits intoscop:mainfrom
Open
refactor: simplify sed/awk/grep uses, etc.#1574akinomyoga wants to merge 6 commits intoscop:mainfrom
akinomyoga wants to merge 6 commits intoscop:mainfrom
Conversation
The variable "prefix" is explicitly initialized when it is declared, so we do not need to explicitly set it to an empty string on this line.
The current implementation does not work for several reasons.
* First, for the selection "|" to work, one needs to enclose the
entire pattern with "@()". The option argument of the "-X" option is
not a regular expression, but an extended glob pattern.
* Next, the option argument of the "-X" option should not be singly
quoted in the present case because command substitutions in the
option argument of "-X" is not going to be expanded.
* Also, one also wants to quote the word of the here string. In Bash
< 4.4, the word of the here string is subject to word splitting, so
it may be affected by IFS.
In addition, we actually do not need to use the "tr" command. We can
reduce the spawn cost by using "${words[*]}" with an appropriate value
of IFS.
"_comp_cmd_tshark__{prefs,protocols}" are mutable global variables
used to cache the prefixes and protocols, so they should have "_mut_"
in the variable names.
scop
approved these changes
Feb 17, 2026
| options=$(module help 2>&1 | command grep -E '^[[:space:]]*\+' | | ||
| _comp_awk '{print $2}' | command sed -e 's/|/ /g' | sort) | ||
| options=$(module help 2>&1 | _comp_awk '/^[[:space:]]*\+/ { | ||
| $0 = $2; gsub(/\|/, " "); print }' | sort) |
Owner
There was a problem hiding this comment.
I have a nagging feeling that there is an awk implementation in existence that does not support gsub, but I can't find it right now and gsub is in POSIX at least down to 2008, so maybe it's all good.
There is one gsub use in the tree in chronyc, but that could be fine if we assume chronyc is Linux specific.
Collaborator
Author
There was a problem hiding this comment.
Isn't that Solaris awk? Solaris <= 11.3 awk indeed doesn't have gsub:
$ awk 'gsub(/a/, "b")' <<< "aaazzz"
awk: syntax error near line 1
awk: bailing out near line 1We use /usr/xpg4/bin/awk (which has gsub) in Solaris through the wrapper _comp_awk, so the problem doesn't happen in Solaris.
I don't have AIX, NetBSD, and OpenBSD, but online manuals seem to suggest that their awk has gsub.
- aix/7.1.0 awk (Mar. 2021)
- OpenBSD-2.2/awk.1 (Dec. 1997, OpenBSD seems to have introduced man pages in 2.2)
- NetBSD-2.0/awk.1 (Jun. 2004, NetBSD seems to have switched from gawk to nawk in 2.0)
- NetBSD-1.3/awk.1 (Nov. 1994, gawk)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.