Using bash , you can use an array like this:
#!/bin/bash VARIABLE=1234-123-456-890 PART=(${VARIABLE//-/ }) echo ${PART[0]}-${PART[1]}-${PART[2]}-${PART[3]}
The extension ${VARIABLE//-/ } changes everything - to spaces, and then breaks the word boundaries into an array.
Alternatively, you can use read :
#!/bin/bash VARIABLE=1234-123-456-890 read PART1 PART2 PART3 PART4 <<< "${VARIABLE//-/ }" echo $PART1-$PART2-$PART3-$PART4
To make it work in sh , you can slightly modify it and set IFS , the input field separator:
#!/bin/sh VARIABLE=1234-123-456-890 old_ifs="$IFS" IFS=- read PART1 PART2 PART3 PART4 <<EOF $VARIABLE EOF IFS="$old_ifs" echo $PART1-$PART2-$PART3-$PART4
Caution: this was tested only with bash in sh mode.
source share