Skip to content

Instantly share code, notes, and snippets.

@pravynandas
Created October 2, 2023 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pravynandas/94628a7e398acaca3dacf0a307e9a45d to your computer and use it in GitHub Desktop.
Save pravynandas/94628a7e398acaca3dacf0a307e9a45d to your computer and use it in GitHub Desktop.
Read csv string into a variable as an array and loop through each element (removing extra spaces).
#!/bin/bash
IFS=,
str="Item1, Item2"
read -ra LIST <<<"$str"
for i in "${LIST[@]}"; do echo "$i" | xargs; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment