IT漫步

技术生活札记©Yaohui

Split string to array by delimiter in shell

#!/bin/bash STR="Sarah,Lisa,Jack,Rahul,Johnson" #String with names IFS=',' read -ra NAMES <<< "$STR" #Convert string to array #Print all names from array for name in "${NAMES[@]}"; do echo $name done #Print index from array for name in "${!NAMES[@]}"; do echo $name done ref: https://tecadmin.net/split-a-string-on-a-delimiter-in-bash-script/

Proudly powered by WordPress