Skip to content

Isolate getopts state and preserve batch PATH order #164

Description

@codeforester

Problem

add_to_path and safe_mkdir reset and mutate the shell-global OPTIND instead of localizing parser state. A caller with OPTIND=9 observes OPTIND=2 after either helper parses one option, which can break subsequent caller-owned getopts processing.

add_to_path -p also reverses a batch: add_to_path -n -p /first /second produces /second:/first:<old-path> even though append mode preserves input order.

Scope

  • Make helper option parsing use a local OPTIND and leave caller state unchanged.
  • Preserve caller argument order for both append and prepend batches.
  • Keep duplicate removal and strict/non-strict directory checks unchanged.

Acceptance Criteria

  • OPTIND has the same value before and after add_to_path and safe_mkdir on success and failure.
  • Prepending /first /second produces /first:/second:<old-path>.
  • Duplicate and missing-directory behavior remains documented and tested.

Validation

  • bats lib/bash/std/tests/lib_std.bats
  • ./tests/validate.sh
  • git diff --check

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions