Skip to content

Instantly share code, notes, and snippets.

@LinArcX
Created June 29, 2020 06:38
Show Gist options
  • Save LinArcX/148991e7b5ae54d02757dbd42f62444a to your computer and use it in GitHub Desktop.
Save LinArcX/148991e7b5ae54d02757dbd42f62444a to your computer and use it in GitHub Desktop.
DEPS=$(echo $1 | cut -d "=" -f 2) # DEPS is a comma-separated list of strings.
1)
IFS="|"
STRING="foo|bar|baz"
set array $STRING
print ${array[0]}
print ${array[1]}
print ${array[2]}
2)
sentence="one;two;three"
sentence=${sentence//;/$'\n'} # change the semicolons to white space
for word in $sentence
do
echo "$word"
done
3)
for i in $(echo $TESTSTR | tr ',' '\n')
do
echo $i
done
4)
for i in ${DEPS//,/ }
do
echo "$i"
done
5)
IFS=';' read -ra VALUES <<< "$DEPS"
## To pritn all values
for i in "${VALUES[@]}"; do
echo $i
done
6)
while [ -n "${DEPS}" ]
do
echo ${DEPS%%;*}
DEPS=${DEPS#*;}
done
7)
for str in ${DEPS//;/ } ; do
echo "+ \"$str\""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment