The reason I stumbled upon this issue in the first place is perhaps it might be related to this awk script not behaving as expected :-
BEGIN {
"set -x ; echo ~'/path/to/file'" | getline output1
"set -x ; echo ~''" | getline output2
"set -x ; echo ~\"/path/to/file\"" | getline output3
print output1
print output2
print output3
}
Running this script :-
❯ gawk -f script.awk
+ echo '~/path/to/file'
+ echo '~'
+ echo '~/path/to/file'
~/path/to/file
~
~/path/to/file
No tilde expansion occurs here as would in an interactive shell or a script.