Skip to content

Commit dbe0e21

Browse files
committed
Fix #4: Choose correct sed option for extended re
The GNU and BSD versions of sed use different options for enabling extended regular expressions. In order for scripts to work on both systems, the flux.sh script needs to check which sed version is installed. This commits adds a check for this. Additionally, the the script is aborted if sed does not seem to support extended regexps at all.
1 parent 2e7f2a9 commit dbe0e21

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main/scripts/flux.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
# end in an unexpected location if CDPATH is not empty.
55
unset CDPATH
66

7+
# This script uses extended regular expressions in sed. As
8+
# there are two ways to enable them, we need to find out what
9+
# the installed version of sed supports:
10+
if echo "" | sed -r "" > /dev/null 2>&1 ; then
11+
extended_regexp="-r"
12+
elif echo "" | sed -E "" > /dev/null 2>&1 ; then
13+
extended_regexp="-E"
14+
else
15+
echo "Error: sed does not seem to support extended regular expressions (neither -r nor -E works)" >&2
16+
exit 2
17+
fi
18+
719
if [ -z "$BASH_SOURCE" ] ; then
820
echo "Error: cannot determine script location (\$BASH_SOURCE is not set)" >&2
921
exit 2
@@ -79,7 +91,7 @@ vars_to_script=$( cat <<'EOF'
7991
q
8092
EOF
8193
)
82-
substitute_vars_script=$( set | sed -r "$vars_to_script" )
94+
substitute_vars_script=$( set | sed $extended_regexp "$vars_to_script" )
8395
# Substitute environment variables in the java options:
8496
java_opts=$( echo "$java_opts" | sed "$substitute_vars_script")
8597

@@ -92,7 +104,7 @@ option_pattern="[^\"' ]*(\"[^\"\\]*(\\\\.[^\"\\]*)*\"|'[^'\\]*(\\\\.[^'\\]*)*'|\
92104
remove_quotes="s/(^[\"'])|(([^\\])[\"'])/\3/g"
93105
java_opts_array=()
94106
while read line ; do
95-
line=$( echo "$line" | sed -r "$remove_quotes" )
107+
line=$( echo "$line" | sed $extended_regexp "$remove_quotes" )
96108
java_opts_array+=("$line")
97109
done < <( echo "$java_opts" | grep -Eo "$option_pattern" )
98110

0 commit comments

Comments
 (0)