Skip to content

Commit d34a509

Browse files
committed
[gh-11363] Fix variable substitution in concat_lines function
The previous fix broke variable substitution because the while loop was running in a subshell. This fix uses a temporary file approach to avoid the subshell issue while still preserving pipe symbols and quoted arguments. Changes: - Use temporary file to process jvm.config content - Avoid subshell that prevented variable substitution - Maintain all existing functionality (comments removal, variable substitution) - Preserve pipe symbols and quoted arguments
1 parent 9dc1597 commit d34a509

File tree

1 file changed

+20
-9
lines changed
  • apache-maven/src/assembly/maven/bin

1 file changed

+20
-9
lines changed

apache-maven/src/assembly/maven/bin/mvn

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,32 @@ find_file_argument_basedir() {
168168
# concatenates all lines of a file and replaces variables
169169
concat_lines() {
170170
if [ -f "$1" ]; then
171-
# Read file line by line, remove comments and empty lines, then perform variable substitution
172-
# This preserves quoted arguments and doesn't split on whitespace within quotes
173-
tr '\r' '\n' < "$1" | \
174-
sed -e '/^$/d' -e 's/#.*$//' | \
175-
while IFS= read -r line; do
176-
# Skip empty lines after comment removal
171+
# Use a temporary file to avoid subshell issues with variable substitution
172+
# First, clean the file: convert CR to LF, remove empty lines and comments
173+
_temp_file=$(mktemp)
174+
tr '\r' '\n' < "$1" | sed -e '/^$/d' -e 's/#.*$//' > "$_temp_file"
175+
176+
# Read each line and perform variable substitution, then concatenate with spaces
177+
_result=""
178+
while IFS= read -r line || [ -n "$line" ]; do
177179
if [ -n "$line" ]; then
178180
# Replace variables
179181
line=$(echo "$line" | sed \
180182
-e "s@\${MAVEN_PROJECTBASEDIR}@$MAVEN_PROJECTBASEDIR@g" \
181183
-e "s@\$MAVEN_PROJECTBASEDIR@$MAVEN_PROJECTBASEDIR@g")
182-
echo "$line"
184+
if [ -z "$_result" ]; then
185+
_result="$line"
186+
else
187+
_result="$_result $line"
188+
fi
183189
fi
184-
done | \
185-
tr '\n' ' '
190+
done < "$_temp_file"
191+
192+
# Clean up temporary file
193+
rm -f "$_temp_file"
194+
195+
# Output the result
196+
echo "$_result"
186197
fi
187198
}
188199

0 commit comments

Comments
 (0)