- Don't put variables in your printf formatting argument as that'll fail when your variable contains printf formatting charcters, e.g. '%'. So use
printf "%s" "$PATH"
instead ofprintf "$PATH"
. - It is never a good idea to use double quotes to delimit an awk script as it introduces double quoting hell in the rest of the script. So use
'/'"${PATH_ROOT//\//\/}"'/{...}'
instead of"/${PATH_ROOT//\//\/}/{...}"
- It is almost never a good idea to allow shell variable expansion to provide parts of the body of your awk script dynamically as it introduces the potential for bizarre syntax errors. So use
awk -v path_root="${PATH_ROOT//\//\/}" '$0 ~ path_root{...}'
instead of'/'"${PATH_ROOT//\//\/}"'/{...}'
. - Rather than test for a condition and use next and then use a print if the condition isn't present, you can just test for the negation of the condition.
- When setting 2 variables to the same value (e.g. RS and ORS), it's clearest to set them together rather than separately.
So, all together, as a starting point your script would be:
PATH_WITHOUT_PYTHONBREW=$(printf "%s" "$PATH" |
awk -v path_root="${PATH_ROOT//\//\/}" 'BEGIN{RS=ORS=":"} $0 !~ path_root' |
sed -e 's#:$##')
assuming your PATH_ROOT manipulation makes sense.
It could be further improved but that should be enough to get rid of your error.