You are not logged in.
I read through this guide: https://wiki.bash-hackers.org/syntax/pe … nd_replace
I'm wondering if I one can substitute multiple occurrences within the same expression. For example, let's say I want to both substitute x86-64 with haswell and simultaneously replace -D_FORTIFY_SOURCE=2, with a null.
CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2,-D_GLIBCXX_ASSERTIONS -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection"
I can do each substitution but I do not know how to string them together:
echo ${CFLAGS/x86-64/haswell}
-march=haswell -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2,-D_GLIBCXX_ASSERTIONS -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection
echo ${CFLAGS/-D_FORTIFY_SOURCE=2,/}
-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_GLIBCXX_ASSERTIONS -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
I "cache" the substitution in the/a variable then then run a second substitution on that, ie.
FOO=bar; FOO=${FOO/b/f}; echo ${FOO/ar/oo}
And I mostly post to subscribe to the topic, cause curious myself ;-)
(But I honestly don't think that it's possible to somehow link substitutions in one expansion)
Offline
@seth - Yep, this is the approach I took, but wanted to see if someone with more knowledge or better search-Fu has an answer
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
You're probably talking about some wizard here …
Offline
Why modify, just append. Appended flags will override earlier statements of the same option on the command line. If you want -march=whatever:
echo $CFLAGS -march=whatever
Whatever other -march flags were already in CFLAGS before this are now irrelevant.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks, Trilby. In one case I need to replace a switch with a null so still two steps.
CFLAGS+=" -march=haswell"
CFLAGS=${CFLAGS/-D_FORTIFY_SOURCE=2,/}
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
You don't need to replace it with "null" do you, as there is a default (isn't 1 the default?). So just overwrite it with the default. But even if you really really do need it removed, you still don't need two steps:
gcc-or-whatever ${CFLAGS/-D_FORTIFY_SOURCE=2,//} -march=haswell
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline