docker-php-extension-installer/scripts/common

50 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

2018-04-11 15:39:10 +00:00
#!/bin/sh
# Reset the Internal Field Separator
2019-12-20 15:52:00 +00:00
resetIFS() {
2018-04-11 15:39:10 +00:00
IFS='
'
}
# Check if a string is in a list of space-separated string
#
# Arguments:
# $1: the string to be checked
# $2: the string list
#
# Return:
# 0 (true): if the string is in the list
# 1 (false): if the string is not in the list
2019-12-20 15:52:00 +00:00
stringInList() {
2018-04-11 15:39:10 +00:00
resetIFS
2019-12-20 15:52:00 +00:00
for stringInList_listItem in $2; do
if test "$1" = "$stringInList_listItem"; then
2018-04-11 15:39:10 +00:00
return 0
fi
done
return 1
}
# Return the strings that are present in two space-separated strings
#
# Arguments:
# $1: the first space-separated string
# $2: the first second-separated string
#
# Output:
# The space-separated list of strings that are present in both lists
2019-12-20 15:52:00 +00:00
commonElements() {
commonElements_result=''
resetIFS
2019-12-20 15:52:00 +00:00
for commonElements_inA in $1; do
if stringInList "$commonElements_inA" "$2"; then
if test -z "$commonElements_result"; then
commonElements_result="$commonElements_inA"
else
2019-12-20 15:52:00 +00:00
commonElements_result="$commonElements_result $commonElements_inA"
fi
fi
done
2019-12-20 15:52:00 +00:00
echo "$commonElements_result"
}