Skip to content

Conversation

@cuonglm
Copy link

@cuonglm cuonglm commented Dec 28, 2022

The current script has some drawbacks:

  • It spawns a sed command for each .age file.
  • If "$PREFIX" contains newline, sed command won't work correctly.
  • Using "$PREFIX" as pattern may lead to code injection.

Fixing those things are simple:

  • cd to "$PREFIX" before running find, we do this in subshell, so no effect to the current shell.
  • Use "find ... -exec sh -c '' sh-find {} +" form, so we can process as much as possible for each exec sh.
  • Use parameter expansion for stripping "./" prefix and ".age" suffix.

The script is now safer, maybe faster, and guarantee to work in all POSIX shells.

The current script has some drawbacks:

 - It spawns a sed command for each .age file.
 - If "$PREFIX" contains newline, sed command won't work correctly.
 - Using "$PREFIX" as pattern may lead to code injection.

Fixing those things are simple:

 - cd to "$PREFIX" before running find, we do this in subshell, so no
   effect to the current shell.
 - Use "find ... -exec sh -c '' sh-find {} +" form, so we can process as
   much as possible for each exec sh.
 - Use parameter expansion for stripping "./" prefix and ".age" suffix.

The script is now safer, maybe faster, and guarantee to work in all
POSIX shells.
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.

1 participant