Skip to content

refactor: simplify uses of sed#1567

Merged
scop merged 6 commits intoscop:mainfrom
akinomyoga:sed-3
Feb 4, 2026
Merged

refactor: simplify uses of sed#1567
scop merged 6 commits intoscop:mainfrom
akinomyoga:sed-3

Conversation

@akinomyoga
Copy link
Collaborator

No description provided.

The idiom `sed -n 's/.../.../p'` already correctly filters the lines.
The same pattern can also be used in the sed expression for curl.
* refactor(function): use tail instead of sed

  "sed -e 1,2d" is interchangeable with "tail -n +3".  This usage of
  "tail" is already used in many places in the codebase.  The current
  sed expression was introduced as "1d" in commit ea10afb and
  modified to "1,2d" in commit 4351ae5.

* refactor(_comp_compgen_p{ids,gids,names}): use tail instead of sed
* refactor(2to3,mcrypt,msynctool,pdftotext): use tail instead of sed

  "sed -e 1d" used in other places can also be replaced with "tail -n
  +2".
Copy link
Owner

@scop scop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

I have a nagging feeling that some POSIX features of basic tools cannot be taken for granted e.g. on Solaris, but I've no easy access to such a box any more, and at least the ones I tried work on FreeBSD, so let's do this.

@scop scop merged commit b92b239 into scop:main Feb 4, 2026
8 checks passed
@akinomyoga akinomyoga deleted the sed-3 branch February 4, 2026 22:47
@akinomyoga
Copy link
Collaborator Author

Thank you.

I have a nagging feeling that some POSIX features of basic tools cannot be taken for granted e.g. on Solaris,

tail -n +2 was already used in many places in the codebase, so I assumed that it runs on a wide environment, but I have a Solaris virtual machine, so I can test it later. As for the sed expressions, I have the feeling that Solaris sed is compliant (unlike Solaris awk), but I haven't checked that the sed expressions actually work in Solaris. Although I'm not sure if I can set up the necessary environment for the full test, I can check the behavior of the sed expressions separately in Solaris at least.

@akinomyoga
Copy link
Collaborator Author

I checked the behavior in Solaris 11.3. It turned out that Solaris tail doesn't support the option -n. It seems to require us to write as tail +2 instead of tail -n +2. However, other compliant implementations of tail don't accept Solaris's tail +2. As usual, Solaris provides the compliant version at /usr/xpg4/bin/tail, which I confirmed accepts -n +2.

I haven't checked the behavior of Solaris 11.4 because I don't have a virtual machine currently, but I found an article (written in Japanese 1) saying that Solaris 11.4 /usr/bin/awk seems to have been updated to be a compliant version. Solaris 11.3 ships with Bash 4.1, and Solaris 11.4 ships with Bash 4.4. This means that we already dropped the support for Solaris 11.3 technically. If we can confirm that Solaris 11.4 awk and tail are indeed POSIX-compliant, maybe we can drop the /usr/xpg4 workaround. Or maybe we should still provide the workaround because the Bash version is actually independent of the version of the standard utilities; users can build and install newer Bash versions in old operating systems, while we reference the operating-system version only for surveying the popular Bash versions in the market.

By the way, do we care about the support for Solaris 11.4? Solaris isn't mentioned in #1429 nor in Minimum bash versions - Wiki. Solaris 11.4 support seems to continue until 2037. If we care about it, we may need to continue to support Bash 4.4 until 2037. We probably want to intentionally ignore Solaris 11.4.

Footnotes

  1. なぜawkの乱数関数でUnix時間を取得できるのか? ~ 乱数の話とUnix時間の深い関係 #UNIX - Qiita

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants