Skip to content

Instantly share code, notes, and snippets.

@olegon
Created October 10, 2022 22:47
Show Gist options
  • Save olegon/c7a843e4b627775b0a65128394ab7d7c to your computer and use it in GitHub Desktop.
Save olegon/c7a843e4b627775b0a65128394ab7d7c to your computer and use it in GitHub Desktop.
#!/bin/bash
IN=$(cat << HMARK
pacotes= a, b, c
testes= 1,2,3,4
HMARK
)
readarray -t LINES <<< "$IN"
for LINE in "${LINES[@]}"; do
if [[ "$LINE" =~ ^pacotes[[:space:]]*=(.*)$ ]]; then
readarray -d "," -t PACKAGES <<< ${BASH_REMATCH[1]}
for PACKAGE in "${PACKAGES[@]}"; do
PACKAGE_WITHOUT_SPACES=$(echo $PACKAGE | xargs)
echo "package = \"$PACKAGE_WITHOUT_SPACES\""
done;
elif [[ "$LINE" =~ ^testes[[:space:]]*=(.*)$ ]]; then
CAPTURED_VALUE=${BASH_REMATCH[1]}
readarray -d "," -t TESTS <<< ${BASH_REMATCH[1]}
for TEST in "${TESTS[@]}"; do
TEST_WITHOUT_SPACES=$(echo $TEST | xargs)
echo "test = \"$TEST_WITHOUT_SPACES\""
done;
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment