Skip to content

Instantly share code, notes, and snippets.

@taikedz
Created February 15, 2023 12:48
Show Gist options
  • Save taikedz/29c31fe347b49c8d928e39d2bdea16e5 to your computer and use it in GitHub Desktop.
Save taikedz/29c31fe347b49c8d928e39d2bdea16e5 to your computer and use it in GitHub Desktop.
Shell: Array split in quoted string
#!/usr/bin/env bash
QUOTED_ARRAY="-Djava=\"one 'and' two\" -Djavax=\"three four\""
while IFS= read -r -d '' item; do echo "$item"; done < <(xargs printf '%s\0' <<< "$QUOTED_ARRAY")
# Output:
# -Djava=one 'and' two
# -Djavax=three four
# obtained from /usr/local/bin/jenkins.sh in the Jenkins sdk17 docker image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment