Skip to main content
added 157 characters in body
Source Link
John1024
  • 76.4k
  • 12
  • 176
  • 165

They don't match because FILTERED_CXXFLAGS has commas and ${TEMP_ARRAY[@]} does not:

Flag: -DNDEBUG
Filtered: -DDEBUG,
Filtered: -DNDEBUG,

If the commas are supposed to be there, then replace:

if [ "$flag" = "$filtered" ]; then

with:

if [ "$flag" = "${filtered%%,}" ]; then

Alternatively, if the commas are not supposed to be there, then replacethe issue is with:

FILTERED_CXXFLAGS=("-DDEBUG", "-DNDEBUG", "-O0", "-O1", "-O2", "-O3", "-Os", "-Og")

One can use declare -p to see what value bash has given to a variable:

$ declare -p FILTERED_CXXFLAGS
declare -a FILTERED_CXXFLAGS='([0]="-DDEBUG," [1]="-DNDEBUG," [2]="-O0," [3]="-O1," [4]="-O2," [5]="-O3," [6]="-Os," [7]="-Og")'

One can see that the commas are included in the value of each element. While many languages require array elements to be separated by commas, Unix shell does not. Instead it treats them as part of the value of the array elements. Thus, replace the above definition with:

FILTERED_CXXFLAGS=("-DDEBUG" "-DNDEBUG" "-O0" "-O1" "-O2" "-O3" "-Os" "-Og")

They don't match because FILTERED_CXXFLAGS has commas and ${TEMP_ARRAY[@]} does not:

Flag: -DNDEBUG
Filtered: -DDEBUG,
Filtered: -DNDEBUG,

If the commas are supposed to be there, then replace:

if [ "$flag" = "$filtered" ]; then

with:

if [ "$flag" = "${filtered%%,}" ]; then

Alternatively, if the commas are not supposed to be there, then replace:

FILTERED_CXXFLAGS=("-DDEBUG", "-DNDEBUG", "-O0", "-O1", "-O2", "-O3", "-Os", "-Og")

with:

FILTERED_CXXFLAGS=("-DDEBUG" "-DNDEBUG" "-O0" "-O1" "-O2" "-O3" "-Os" "-Og")

They don't match because FILTERED_CXXFLAGS has commas and ${TEMP_ARRAY[@]} does not:

Flag: -DNDEBUG
Filtered: -DDEBUG,
Filtered: -DNDEBUG,

If the commas are supposed to be there, then replace:

if [ "$flag" = "$filtered" ]; then

with:

if [ "$flag" = "${filtered%%,}" ]; then

Alternatively, if the commas are not supposed to be there, then the issue is with:

FILTERED_CXXFLAGS=("-DDEBUG", "-DNDEBUG", "-O0", "-O1", "-O2", "-O3", "-Os", "-Og")

One can use declare -p to see what value bash has given to a variable:

$ declare -p FILTERED_CXXFLAGS
declare -a FILTERED_CXXFLAGS='([0]="-DDEBUG," [1]="-DNDEBUG," [2]="-O0," [3]="-O1," [4]="-O2," [5]="-O3," [6]="-Os," [7]="-Og")'

One can see that the commas are included in the value of each element. While many languages require array elements to be separated by commas, Unix shell does not. Instead it treats them as part of the value of the array elements. Thus, replace the above definition with:

FILTERED_CXXFLAGS=("-DDEBUG" "-DNDEBUG" "-O0" "-O1" "-O2" "-O3" "-Os" "-Og")
Source Link
John1024
  • 76.4k
  • 12
  • 176
  • 165

They don't match because FILTERED_CXXFLAGS has commas and ${TEMP_ARRAY[@]} does not:

Flag: -DNDEBUG
Filtered: -DDEBUG,
Filtered: -DNDEBUG,

If the commas are supposed to be there, then replace:

if [ "$flag" = "$filtered" ]; then

with:

if [ "$flag" = "${filtered%%,}" ]; then

Alternatively, if the commas are not supposed to be there, then replace:

FILTERED_CXXFLAGS=("-DDEBUG", "-DNDEBUG", "-O0", "-O1", "-O2", "-O3", "-Os", "-Og")

with:

FILTERED_CXXFLAGS=("-DDEBUG" "-DNDEBUG" "-O0" "-O1" "-O2" "-O3" "-Os" "-Og")