Created
June 29, 2020 06:38
-
-
Save LinArcX/148991e7b5ae54d02757dbd42f62444a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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