name = "env_path_builder" category = "environment" mode = "convert" description = """ Read directory paths from stdin, one per line. Append each to the MYPATH environment variable (colon-separated), skipping duplicates. The initial value of MYPATH is provided via the environment (may be empty). Print the final value of MYPATH to stdout. """ bash_source = """ #!/bin/bash while IFS= read -r dir || [[ -n "$dir" ]]; do if [[ -z "$MYPATH" ]]; then export MYPATH="$dir" elif [[ ":$MYPATH:" != *":$dir:"* ]]; then export MYPATH="$MYPATH:$dir" fi done echo "$MYPATH" """ [[test_cases]] stdin = """/usr/local/bin /usr/bin /usr/local/bin /opt/bin""" expected_stdout = "/usr/local/bin:/usr/bin:/opt/bin" env = { "MYPATH" = "" } [[test_cases]] stdin = """/new/path /existing""" expected_stdout = "/already/here:/new/path:/existing" env = { "MYPATH" = "/already/here" } [[test_cases]] stdin = "/only" expected_stdout = "/only" env = { "MYPATH" = "" }