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
Problem
add_to_pathandsafe_mkdirreset and mutate the shell-globalOPTINDinstead of localizing parser state. A caller withOPTIND=9observesOPTIND=2after either helper parses one option, which can break subsequent caller-ownedgetoptsprocessing.add_to_path -palso reverses a batch:add_to_path -n -p /first /secondproduces/second:/first:<old-path>even though append mode preserves input order.Scope
OPTINDand leave caller state unchanged.Acceptance Criteria
OPTINDhas the same value before and afteradd_to_pathandsafe_mkdiron success and failure./first /secondproduces/first:/second:<old-path>.Validation
bats lib/bash/std/tests/lib_std.bats./tests/validate.shgit diff --check