Let’s say that you’re in a system with harmful filenames, for eg.
set lnk = ''to
to "'
ln -s ' tata ' $lnk:q
Now I use lnk
as argument of a command inside backticks:
echo '=expected output='
readlink $lnk:q
echo =1=
printf '%sn' `readlink $lnk:q`
echo =2=
printf '%sn' "`readlink $lnk:q`"
echo =3=
printf '%sn' "`readlink "$lnk"`"
echo =4=
printf '%sn' "`readlink '$lnk:q'`"
=expected output=
tata
=1=
tata
=2=
Unmatched '''.
=3=
Unmatched '`'.
=4=
Unmatched '"'.
What would be the correct way to escape a variable in double-quoted backticks?