On Sat, Oct 25, 2025 at 01:38:51PM -0400, Greg Wooledge wrote:
> On Sat, Oct 25, 2025 at 11:52:25 -0500, Maksym Telychko wrote:
> >     Following code produces unexpected results:
> > 
> >     pat='\*'
> >     echo $pat
> 
> echo "$pat"
> 
> Or even better: printf '%s\n' "$pat"
> 
> The double quotes are NOT optional.  They are 100% required.

I believe that they are intentionally leaving the expansion unquoted
to have the shell perform pathname expansion on the variable contents.
The issue is that the backslash is preventing the asterisk from being
treated as a wildcard, so the user is confused about why the expected
expansion (and matching of the file called \*123) is not happening.

What they probably want is:

        echo "$p"*

or

        printf '%s\n' "$p"*

-- 
Matti Andreas Kähäri
Uppsala, Sweden

.

Reply via email to