Summary: You probably have echo $p
somewhere in your code. You need to double-quote $p
.
No, *
is not treated as the ls
command. It is, however, treated as a filename globbing pattern due to being used unquoted somewhere (not in code shown in the question)
You need to take care both when assigning and using the value of p
and use appropriate quoting to protect the string.
Filename globbing patterns are not expanded in here-strings:
$ cat <<< *
*
So there is nothing wrong with the unquoted use of $p
in the call to sed
. However, it is almost always better to explicitly quote variable expansions. See also the unquoted use of $fname
in your test. That should be double quoted for sure.
You say that the script outputs the text
>= (short)BigBlock file1 file2 file3 DISK_SIZE + Size)
There is nothing that would provoke this string to be outputted in the script shown in the question. This is probably due to you doing
echo $p
somewhere else in the script.
Again, use double quotes around $p
:
echo "$p"
This way, you stop the shell from performing file name globbing on its value (expanding *
).
In general, use echo
only for static strings, and use printf
for variable data:
printf '$p is "%s"\n' "$p"
Related to that last point: Why is printf better than echo?
$p
. – Kusalananda Sep 22 '17 at 17:29